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.
Hi!I have an command to read inputs from file2 and replace the content in file1. Issue is that the op is coming in a single line as gsub and split functions don't recognize new line characters. Can someone plz suggest how to get the op in format given below:
Code:
awk 'NR==FNR{gsub(/input./,""); split($0,a," = ");b[a[1]]=a[2];next} {gsub(/@/,"");for (i in b) gsub(i,b[i])}1' $t2 $t3
I cannot reproduce the problem. Actually your code should work as expected: the print action triggered by the 1 at the end should print out the current record on its own line. Is this code part of a script? Maybe there is something else that prevents the printing of newlines (typically an echo command).
Thank you all for your response Yes.It is part of a script.I have edited the exact contents of the t3 file.is it because of the extra parameters in t3 that my op is in a single line?If yes,plz help me to correct my awk command.Thanks again!
I think you are not understanding us. Your script and data work for us as is, no changes required. Although, noticing now that you are in windows, was either file
written in windows?? If so you will find there are pesky little control characters at the end of the line that can throw you a curve.
Try running dos2unix over it and see if the same script now works.
It would be useful if you posted the updated version of the t3 file and the relevant part of the script? Is the output of awk command stored into a shell variable, then printed out? Also you can give a try to grail's suggestion, since it is one of the first causes for weird problems in shell scripting.
I have a problem with slashes now.If I have 4 slashes (\\\\) in my input file, they get converted to single slash in op (\). I tried using /\/\ in my input file but it didnt help. Can someone suggest how do I get the exact \\\\ in my op? I have edited teh ip and required op fields.
Again it works for me. Please, tell us which version of awk are you running and which is your OS. You're posting from a Windows system and if you run the awk command under cygwin or using the unix tools for windows can be relevant. GNU awk on a Linux system work as expected:
I am using the awk statement in a shell script on an AIX server. I tried awk --version but its showing me error:
awk --version
awk: Not a recognized flag: -
Usage: awk [-F Character][-v Variable=Value][-f File|Commands][Variable=Value|File ...]
Is it because awk doesnt behave the same way on AIX machines?
Edit: Found this in the changelog for 4.0.0, but not sure if it is the cause:
The GNU awk manual is not clear about this point. Anyway I get the same behavior (that one you've reported) with gawk 4.0.0. I will deepen into this issue.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.