Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check number of lines in a file

Status
Not open for further replies.

chino10

Technical User
Jun 23, 2011
16
US
I have a file that will have zero or more lines of data. What I need to do first is check the file to see if it has zero or 1 line of data. If it does I need to copy it to a specific directory as is, otherwise I need to run a function (which I already have) against it before sending it to the same specific directory.

Current script example:

Code:
gawk -f Function.awk input

I suppose what I am looking for is an IF/ELSE script stating:

Code:
gawk -f IF input has zero or 1 line of data then copy to directory ELSE Funtion.awk input

Any ideas regarding this issue would be greatly appreciated. Thank you.
 
something like this?

Code:
END {

  if( (NR==0) || (NR==1)  )
    system("cp  inFile.txt  copy_of_inFile.txt");
  else
  {
    run_a_function();
    copy_results();
  }

}
 
I would do something like:

Code:
[[[[ "$(wc -l input)" -le 1 ]]]] && gawk -f Function.awk input || cp input input.tooshort

Annihilannic
[small]tgmlify - code syntax highlighting for your tek-tips posts[/small]
 
D'oh, mixed up my logic, that should be -gt (for greater than), not -le (less than or equal to).

Annihilannic
[small]tgmlify - code syntax highlighting for your tek-tips posts[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top