Get awk to work in bash script
Ok so I realize running awk within a bash script may not work because the shell itself tries to interpret the awk options. But I can't figure out how to get my command to work.
Code:
#!/bin/bash Debian Jessie |
Did you check if files meet awk condition? ie if ips.txt has more than 7 lines, if ipstr.txt contains lines with more than 5 chars...
|
edit: I should learn to read....never mind.
|
bash is a commandline interpreter
you should see a prompt such as "#" for root or "$" for user (which you didn't show above) $ echo "hi" | awk '{print}' ; echo "lo" | awk '{print}' OR $ echo "hi" | awk '{print}' $ echo "lo" | awk '{print}' OK - so maybe you saw a prompt and pressed enter (bash would tell you if the command didn't execute, awk would tell you if you had a syntax error. What your telling me is either or both of the .txt had no data. (you should know which, but you didn't say). What that says is awk didn't find what you searched for. 'FNR > 7 {...}' is meaningless in awk as far as I know awk's manpage says: "pattern {action}", it does not say "pattern | expression {action}" $ cat foo | awk '(FNR>0){print $1}' # apparently, to pass off an expressions instead of using pattern, you need parenthesis (evaluation of expression occurs in parenthesis may occur and decide outcome - in some languages when this happens is tricky) $ cat foo | awk '{if(FNR > 0) {print $1}}' # in this example no pattern (means all records), FNR is tested once per record, which is really the same as the above |
You can put the awk part in an awk script and call it from the bash script.
|
I wouldn't do it as posted, but it should work fine if data are provided correctly. awk honours (some) short-forms, so the FNR test is ok.
|
@silver007:
In order for anyone to see what may be happening you need to supply a few example lines from each file, and tell us what you expect the output of awk to be in each case. If your data in ips.txt matches the awk condition, then it should write to ipstr.txt according to the awk expression, similarly for the second awk statement. If it is not doing what you want then it is likely that the data are not what you expect, or your awk expressions do not match them... either way, we need to see some example data and know what you expect the result to be. |
All times are GMT -5. The time now is 06:57 AM. |