This solution will work when you need to add variable at the last of the line. If any conditions are there for the variable to be added please let us know with full description, but if you need to add variable at last solution will work. Explaination of the solution is as follows. $(NF+1) means I am adding one more field at last of the line as a line will have acually NF number of fields only, then I am giving 1 which means I am making condition part set to true so be default print operation will take place. Please refer man awk also for same, will be helpful for you.
EDIT: Please use the following solution for same as above solution will not give requested output, thanks Franklin for pointing it out.
Thanks,
R. Singh
Last edited by RavinderSingh13; 09-01-2014 at 11:44 AM..
Reason: Adding correct solution to the thread
This solution will work when you need to add variable at the last of the line. If any conditions are there for the variable to be added please let us know with full description, but if you need to add variable at last solution will work. Explaination of the solution is as follows. $(NF+1) means I am adding one more field at last of the line as a line will have acually NF number of fields only, then I am giving 1 which means I am making condition part set to true so be default print operation will take place. Please refer man awk also for same, will be helpful for you.
Thanks,
R. Singh
doesn't give the correct output.
You should surround the command with braces:
or
If you add a field with a value which is not empty, awk considers the action as true, so a 1 is superfluous.
Hi All,
I have a file with a pipe delimiter. I need to replace the delimiter with html tags.
I managed to get all the delimiters replaced along with first and last but the requirement is that I need to change 7th delimiter with slight change.
File1:
... (2 Replies)
I have an xml file dumped from rrd file, that I want to "patch" so the xml file doesn't contain any blank hole in the resulting graph of the rrd file.
Here is the file.
<!-- 2015-10-12 14:00:00 WIB / 1444633200 --> <row><v> 4.0419731265e+07 </v><v> 4.5045912770e+06... (2 Replies)
Have Pipe Delimited File:
> BRYAN BAKER|4/4/2015|518 VIRGINIA AVE|TEST
> JOE BAXTER|3/30/2015|2233 MockingBird RD|ROW2On 3rd column where the address is located, I want to add a space after every numeric value - basically doing a "s//&\ / ":
> BRYAN BAKER|4/4/2015|5 1 8 VIRGINIA AVE|TEST
> JOE... (5 Replies)
This is a file that I have
test line 1 (55)
)
test line 2 (45)
)
I would like to change all the parens in position 1 of this file to a );
i only want to check position 1 in every line of the file. I have tried different varations of sed, but cannot seem to be able to limit it to... (1 Reply)
Input file:
ASD_QAW 12 A_@
AE_AQ 21 PA_123
ASDA_@ 23 ADA_AS
.
.
Output file:
ASD_QAW 12 A @
AE_AQ 21 PA 123
ASDA_@ 23 ADA AS
.
.
Do anybody know how to just specific and replace "_" in column 3 with tab delimiter (\t)?
Thanks for advice. (2 Replies)
Hi all,
I have two files with the following format:
file1
BBB;33
AAA;2
CCC;5
file2
5;.;.;.
33;.;.;.
The first file contain a list of code and numbers. The second file only the number.
I would like to replace the corresponding code in the first column of the file1 with the... (3 Replies)
Can anyone please help with this? I have 2 files as given below.
If 2nd column of file1 has pattern foo1@a, find the matching 1st column in file2 & replace 2nd column of file1 with file2's value.
file1
abc_1 foo1@a ....
abc_1 soo2@a ...
def_2 soo2@a ....
def_2 foo1@a ........ (7 Replies)
using sed to replace a specific string on a specific line number using variables
this is where i am at
grep -v WARNING output | grep -v spawn | grep -v Passphrase | grep -v Authentication | grep -v '/sbin/tfadmin netguard -C'| grep -v 'NETWORK>' >> output.clean
grep -n Destination... (2 Replies)
Hi
My orginal file is like (100s of lines)
id host ip location remarks
1 host1 ip1 - xxx
2 host2 ip2 - xxx
3 host3 ip3 - xxx
--
--
9 host9 ip9 - xxx
I have a ref file like
host1 location1
host2 location2
host3 location3
--
--... (6 Replies)