How to compare that file name is empty?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to compare that file name is empty?
# 8  
Old 12-07-2009
you can also use grep's exit status $? to check if there is a pattern or not. if there is a pattern exit value is 0, otherwise 1.

Code:
mo@mo-laptop:~$ ls | grep scripts
scripts
mo@mo-laptop:~$ echo $?
0
mo@mo-laptop:~$ ls | grep nofilehere
mo@mo-laptop:~$ echo $?
1

just put it in an if-then statement.

in bash:

Code:
grep something
if [ $? == 1 ]; then
      do something
fi



---------- Post updated at 11:35 PM ---------- Previous update was at 11:34 PM ----------

oops, someone beat me to it
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to reformat output if input file is empty, but not if file has data in it

The below awk improved bu @MadeInGermany, works great as long as the input file has data in it in the below format: input chrX 25031028 25031925 chrX:25031028-25031925 ARX 631 18 chrX 25031028 25031925 chrX:25031028-25031925 ARX 632 14... (3 Replies)
Discussion started by: cmccabe
3 Replies

2. Shell Programming and Scripting

if/else with an empty file...

Hi there, I'm just starting out with shell scripting and I'm trying to make a test where the script will basically run yum check-update to find out if the server has any available and if it does it e-mails me but if not it will just stop there. I have it working if there are actually... (7 Replies)
Discussion started by: Imnewtothis
7 Replies

3. Red Hat

Compare Empty Variable

Hello All, I am running the below code in my script. I want if jk is empty nothing should be appened to the file total_usage. but apparently its not happening.Kindy let me know how to do it. ################################### jk=`ps auxf |grep -w $inputline|tr -s " "|cut -d... (0 Replies)
Discussion started by: ajaincv
0 Replies

4. Shell Programming and Scripting

Compare columns and rows with template, and fill empty slots.

Hi, I'm working on a script that will take the contents of a file, that is in a row and column format, and compare it to a arrangment file. Such that if there is any or all blanks in my content file, the blank will be filled with a flag and will retain the row and column configuration. Ex. ... (2 Replies)
Discussion started by: hizzle
2 Replies

5. Shell Programming and Scripting

while file is empty

how can i use while loop ? while file is empty do.... if not empty do ..... in bash (1 Reply)
Discussion started by: Trump
1 Replies

6. UNIX for Dummies Questions & Answers

Getting same exit status for empty and non empty file

Hi All, I am checking for a empty input file to do some further action , but I am getting exit status 0 in both the cases , for empty and non empty file both. The value of $? is coming 0 in if part also and else part too. #!/bin/ksh if ]; then echo "data" # exit 0 echo "$?" else... (4 Replies)
Discussion started by: mavesum
4 Replies

7. Shell Programming and Scripting

how to see if the file is empty or not?

hi how can I determine, if a file is empty or not?I am using read line clause. The script should be like: while read line do if(file is empty) then; ...... done < $blacklist (1 Reply)
Discussion started by: tjay83
1 Replies

8. UNIX for Dummies Questions & Answers

Trying to empty file using > but the file size increasing when next append

AIX 5.3 / KSH I have a Java application which creates a log file a.log. I have a KSH script which does the following action cp a.log /directory2/b.log > a.log After this the file size goes to 0 as per "ls -l" Then next time when the application writes into this file, the file size... (4 Replies)
Discussion started by: firdousamir
4 Replies

9. Shell Programming and Scripting

File is not empty?

How do I check to make sure a file is not zero bytes? Something like: if then ????? (7 Replies)
Discussion started by: lesstjm
7 Replies

10. UNIX for Advanced & Expert Users

empty file in hp-ux

Hi, I need your help. How can I create an empty filename with a specific size, in hp-ux? Regards, Mizi (2 Replies)
Discussion started by: Mizi
2 Replies
Login or Register to Ask a Question
mcx ctty(1)							  USER COMMANDS 						       mcx ctty(1)

  NAME
      mcx ctty - compute betweenness centrality for network nodes

  SYNOPSIS
      mcx ctty [options] [matrix-file]

      mcxctty  is not in actual fact a program. This manual page documents the behaviour and options of the mcx program when invoked in mode ctty.
      The options -h, --apropos, --version, -set, --nop, -progress <num> are accessible in all mcx modes. They are described  in  the  mcx  manual
      page.

      mcx  ctty  [-abc	<fname> (specify label input)] [-imx <fname> (specify matrix input)] [-extent <int> (only consider paths of length at most
      <int>)] [-o <fname> (output file name)] [-tab <fname> (use tab file)] [-t <int> (use <int> threads)] [-J <intJ> (a total of <intJ> jobs  are
      used)]  [-j  <intj>  (this  job has index <intj>)] [-h (print synopsis, exit)] [--apropos (print synopsis, exit)] [--version (print version,
      exit)]

  DESCRIPTION
      mcx ctty computes betweenness centrality for all nodes in a graph, using the between centrality update algorithm from [1].

      The input graph/matrix, if specified with the -imx option, has to be in mcl matrix/graph format. You can use label input	instead  by  using
      the  -abc  option.   Refer  to  mcxio(5) for a description of these two input formats.  By default mcx diameter reads from STDIN and expects
      matrix format.  To specify label input from STDIN use -abc -.

  OPTIONS
      -abc <fname> (label input)
	The file name for input that is in label format.

      -imx <fname> (input matrix)
	The file name for input. STDIN is assumed if not specified.

      -o <fname> (output file name)
	The name of the file to write output to.

      -extent <int> (only consider paths of length at most <int>)
	This option will lead to different results. Results will still be informative however, being representative for the local context in which
	nodes reside. It does probably not make sense to use values smaller than four or five.

      -tab <fname> (use tab file)
	This  option causes the output to be printed with the labels found in the tab file.  With -abc this option will, additionally, construct a
	graph only on the labels found in the tab file.  If this option is used in conjunction with -imx the tab domain and the matrix domain  are
	required to be identical.

      -t <int> (use <int> threads)
      -J <intJ> (a total of <intJ> jobs are used)
      -j <intj> (this job has index <intj>)
	Computing  centrality  scores in a graph is time-intensive.  If you have multiple CPUs available consider using as many threads. Addition-
	ally it is possible to spread the computation over multiple jobs/machines.  Conceptually, each job takes a  number  of	threads  from  the
	total  thread  pool.  If  job control is used (the -J option is used) then the number of jobs should not exceed the number of threads. The
	total number of threads divided by the total number of jobs defines the number of threads that will be used by the current job.  Addition-
	ally,  the  number  of	threads specified signifies the total added amount of all threads across all machines and must be the same for all
	jobs. This number is used by each job to infer its own set of tasks.  The following set of options, if given to as many commands,  defines
	three jobs, each running four threads.

	-t 12 -G 3 -g 0
	-t 12 -G 3 -g 1
	-t 12 -G 3 -g 2

  REFERENCES
      [1]  Ulrik  Brandes, A Faster Algorithm for Betweenness Centrality.  Journal of Mathematical Sociology 25(2): 163-177, (2001).  http://cite-
      seerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.11.2024

  SEE ALSO
      mcxio(5), and mclfamily(7) for an overview of all the documentation and the utilities in the mcl family.

  mcx ctty 12-068						      8 Mar 2012							 mcx ctty(1)