Hello,
I have a text file withe some records
20121031|5
20121030|3
20121029|1
20121028|4
20121027|6
I want to search for a patten with '20121030' and then increment the second part of the delimiter i.e. 3 by 1 to make it 4 to look like
20121031|5
20121030|4
20121029|1
20121028|4
20121027|6
thanks for the help.
Yoda
2
awk -F"|" ' { OFS="|" } /20121030/ { print $1,$2+1; } ' file
Thanks bipinajith. Works perfectly.
pamu
4
@bipinajith - It will print only lines having 20121030 in it...
Try
awk '{FS=OFS="|" }/20121030/{$2+=1}1' file
Yoda
5
Oh right, I misread requester's requirement.:wall: Thanks for correcting.
Thanks bipinajith and pamu
perl -F'/[|]/' -alpe 'if($F[0] eq "20121030"){$F[1]+=1;print join "|",@F;next}' file
$ awk -F\| -v OFS=\| '/20121030/{$2+=1}1' a.txt
20121031|5
20121030|4
20121029|1
20121028|4
20121027|6