Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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
Last edited by X-LFS-2010; 03-05-2018 at 10:07 PM.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.