INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Check number of lines in a file

Check number of lines in a file

(OP)
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.

RE: Check number of lines in a file

something like this?

CODE

END {

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

} 

RE: Check number of lines in a file

I would do something like:

CODE

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

Annihilannic
tgmlify - code syntax highlighting for your tek-tips posts

RE: Check number of lines in a file

D'oh, mixed up my logic, that should be -gt (for greater than), not -le (less than or equal to).

Annihilannic
tgmlify - code syntax highlighting for your tek-tips posts

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close