Results 1 to 2 of 2
Hi Everybody
I have the following file with 5 fields which are seperated by '|'
Eno |Ename |Designation |dept |sal
5000 |Sharma |Director |Production |5000
6000 |guptha |Director |personnel |20000
...
- 05-27-2008 #1Linux Newbie
- Join Date
- Jul 2004
- Posts
- 143
reg awk
Hi Everybody
I have the following file with 5 fields which are seperated by '|'
Eno |Ename |Designation |dept |sal
5000 |Sharma |Director |Production |5000
6000 |guptha |Director |personnel |20000
7000 |varma |Director |finance |5000
My requirement is I want to change the value of 5th field(sal) to 10000 if it is 5000.
My output will be like this
Eno |Ename |Designation |dept |sal
5000 |Sharma |Director |Production |10000
6000 |guptha |Director |personnel |20000
7000 |varma |Director |finance |10000
I am using the following one.
awk -F"|" '{if ($5==5000) $5=10000;print}' <filename>
But the field seperator in the output will be space instead of a | like below where the sal field is 5000.
Eno |Ename |Designation |dept |sal
5000 Sharma Director Production 10000
6000 |guptha |Director |personnel |20000
7000 varma Director finance 10000
Please help me to get the field seperator as |
Thanks InAdvance,
Mummaneni.
- 05-27-2008 #2
hi,
-F (which equals FS) is just the input field separator. here you need to set the output field separator.
so you go like this
Code:awk '{BEGIN { FS = "|"; OFS = "|"} {if ($5==5000) $5=10000;print}' <filename>Linux and me it's a love story


Reply With Quote