I am writing a bash script.

setenv lineNUM `grep -n ms-listviewtable wget_list.log | awk '{print $1}' | cut -d ':' -f 1`
setenv next `expr $lineNUM + 2`
echo `awk '{FNR>=$lineNUM && FNR<=$next}' wget_list.log`

It returns me with the following syntax error.

awk: {FNR>=$lineNUM && FNR<=$next}
awk: ^ syntax error

Anything wrong here?

  • There are a number of things wrong there. 1) setenv is not part of bash, so you are using some shell other than bash, maybe csh. 2) An awk statement is generally of the form /pattern/{action}. You are putting your pattern within the braces of the action part. 3) Awk doesn't know about environment variables, so you'll have to surround your awk program with " instead of ' and let the shell expand those variables, or use some other method to get those values into your awk program. 4) You don't need the last echo. The awk command without the surrounding `s will print the result. – garyjohn Apr 19 '14 at 3:33

You've got a condition, but no action in your awk program. Try this:

awk '{if(FNR>=ENVIRON["lineNUM"] && FNR<=ENVIRON["next"]) print $0}' wget_list.log

Or just:

head $next | tail -n +$lineNUM wget_list.log

Print a file skipping first lines

  • @user2052801 I'm glad we could help. Voting and accepting answers is a great way to give thanks too. – Basilevs Apr 19 '14 at 4:02
  • @Bailevs - I can only accept as i cannot vote because of the reputation lacking. – user2052801 Apr 19 '14 at 4:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.