I hava a csv(delimiter:commaseparated) file like this
a,b,c,d
There are approximate 10000 lines in csv file like above.
Whatever written at last field i have to change with ‘e’.
Eg.
Input file
a,b,c,d
e,f,g,h
i,j,k,l
m,n,o,p
Output file
a,b,c,e
e,f,g,e
i,j,k,e
m,n,o,e
As you can see d(first line last element),h(second line last element),l(third line last element),p(fourth line last element)
…All are replaced by ‘e’.
How can i change this by shell scripting on linux.
One way using awk:
$NFindicates the last field of the file. Just by setting “e” to $NF gets your job done. 1 is to print every line.-F=> to specify the input field separator,OFS=> to specify the o/p field separatorOne more option using sed:
To change the file in place using GNU sed:
sed matches the pattern till the last comma and groups it which is available is
\1. By just appending “e”, we get the solution.