This is my file.
NAME|NUM|ADDR|AGE
abcd|02|abc|cd|12
jake|04|xy|zzb|12
lau|92||xcx| 56
My desired output has to be like this
NAME|NUM|ADDR|AGE
abcd|02|abc#cd|12
jake|04|xy#zzb|18
lau|92|#xcx| 56
My file had 4 fields and the 3rd col has a pipe delimiter in between the characters like "ice|cream", my requirement is to replace the | field in the 3rd with any value like (#,* or anything). Since this is pipe delimited file i'm unable to replace that particular part of the file exclusively.Any help will be very useful for me..thanks
awk solution:
NR==1;
- print the 1st record as isNR>1 && NF>4
- check if record has excessive fields$3"#"$4
- implode the 3rd and 4th fields replacing separator with a new char#
The output:
Or if you want a more traditional logic based solution, (and admittedly painfully long-handed ;-/) here is another solution
output
I've added comments to code to explain what is going on.
Here it is as a the all-important one-liner ;->
IHTH
Just set
n
to the number of whichever field you want to combine with the field after it: