I have a trouble in writing a sed command to add a value to each record as new field , next to the last column (sometimes values being null), in a csv file using sed command.
For Example, below is my sample csv data (taking last few fields and few records only). I need to add a new value under the header after 'ShipFromStore' field to every record of the file.
Sample Input (There are fields ahead but copied only few of them ending with :
Allocation% ValidityFrom ValidityTo CODsurcharge ShipFromStore
22 1/10/2017 9/30/2019 4.5
22 1/10/2017 9/30/2019 4.5
22 1/10/2017 9/30/2019 4.5
Desire Output :
Allocation% ValidityFrom ValidityTo CODsurcharge ShipFromStore NewField
22 1/10/2017 9/30/2019 4.5 160
22 1/10/2017 9/30/2019 4.5 160
22 1/10/2017 9/30/2019 4.5 160
ShipFromStore values are null for now but in the future we might be receiving data
Tried below commands but unable to achieve it.
sed 'N;s/","/",'160',"/77' Filename
#77 being the position after which the value is to be added
sed 's/$/\,'160'/' Filename
sed '1{s/$/,"Batch_Id"/;b};s/$/,'"$c"'/' Filename