I have one file called abc.csv, its format is:


I want to delete size: , and the file will become like this:


Can anyone tell me how to use shell script to perform this task?

2 Answers 2


You can use sed easily for this task:

sed -i -- 's/size://' abc.csv

s/size:// is a simple regex that says replace size: with <blank>.

  • 1
    Perfect ! It works on me. Thank You so much. :)
    – technoob
    Commented Sep 25, 2015 at 13:43

Below is a useful alternative command for Unix users whose version of sed does not support the -i flag (such as Solaris -- and also OS X, which ships with BSD sed by default).

sed 's/size://' abc.csv > tmpfile; mv tmpfile abc.csv

The g option at the end of the sed command is not required in your specific example, because 'size:' doesn't appear more than once per line.

EDIT: For smaller files, you could also store the updated content in a variable, in order to avoid creating an unnecessary temporary file:

new="$(sed 's/size://' abc.csv)"; echo "$new" > abc.csv

This method would also allow the ability to echo the "$new" variable (updated file) to STDOUT for sanity checking purposes before overwriting the original file.

You must log in to answer this question.