Hi - I have the below file format and i want to update a value in the line that start with C3
C1, 2,2,0,9292016_101425, 0, 9292016_101428, 0, 9292016_101428
C2, 1,2,0,9292016_101425, 0, 9292016_101428
C3, 2,2,0,9292016_101425, 0, 9292016_101428, 0, 9292016_101428
I want to update the above C3 line as below (just changed 0 to 1 in the fourth field)
C3, 2,2,1,9292016_101425, 0, 9292016_101428, 0, 9292016_101428
the problem i have is i know how to append a string to a file but i dont know how to modify a particular line content in a file.
Any help will be greatly appreciated.
perl -pe 's/^C3,.*,.*,\K0,/1,/' oldfile >newfile
or to update oldfile itself:
perl -i -pe 's/^C3,.*,.*,\K0,/1,/' oldfile
or to backup the original file to oldfile.bak and then update oldfile:
perl -i.bak -pe 's/^C3,.*,.*,\K0,/1,/' oldfile
Too lengthy?