formatting op of awk command
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 Code:
RANGE:DUMMY:REMOTE_SYSTEM=DUMMY FILE_OPTION=REPLACE CODE_FLAG=ASCII USERID=DUMMY PASSWORD=DUMMY COMPRESS=YES QUEUE=NO:REMOTE_FILE=DUMMY:RECLASS:DUMMY:REMOTE_SYSTEM=DUMMY FILE_OPTION=REPLACE CODE_FLAG=ASCII USERID=DUMMY PASSWORD=DUMMY COMPRESS=YES QUEUE=NO:REMOTE_FILE=\DUMMY\ANBDGD\KASLLS\AKLLS: Code:
RANGE:DUMMY:REMOTE_SYSTEM=DUMMY FILE_OPTION=REPLACE CODE_FLAG=ASCII USERID=DUMMY PASSWORD=DUMMY COMPRESS=YES QUEUE=NO:REMOTE_FILE=\\\\DUMMY\\ANBDGD\\KASLLS\\AKLLS: t2 content- Code:
input.xcom.range.hostname = DUMMY Code:
RANGE:@xcom.range.hostname@:REMOTE_SYSTEM=@xcom.range.remote_system@ FILE_OPTION=REPLACE CODE_FLAG=ASCII USERID=@xcom.range.userid@ PASSWORD=@xcom.range.password@ COMPRESS=YES QUEUE=NO:REMOTE_FILE=\\\\@xcom.range.remote_file_system @: |
Hi and welcome to LinuxQuestions!
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). |
Works here too :)
|
Works.
(Fedora 14 - GNU Awk 3.1.8) |
formatted the exact content
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.
|
Hi All,
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:
Code:
$ cat > t2 |
Ditto on output:
Code:
$ awk --version 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 Edit: Found this in the changelog for 4.0.0, but not sure if it is the cause: Quote:
|
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? |
Quote:
|
I cannot use nawk or gawk as it is not availbale.Is there any work around for this?
|
Quote:
|
Hard to say for a solution as your awk is showing a different result, ie all four being converted to one is an anomaly that I cannot replicate.
|
All times are GMT -5. The time now is 08:54 AM. |