Looking for a short way to summarise many sed commands

Hello,

I have a large number of sed commands that I execute one after the other, simply because I don't know if there's a shorter way to do it. I hope someone can help me save some time :slight_smile:

These are my commands:

1.) remove all " in the file:

    sed -e 's/\"//g' file

2.) insert ( and space at the beginning of each line:

    sed 's/^/( /' file

3.) insert " ) at the end of each line:

     sed 's/$/\" )/' file

4.) insert blizzard_ at position 9:

    sed 's/./blizzard_/9' file

5.) insert space and " at position 22:

     sed 's/./ \"/22' file

6.) delete 5th and 6th character in each line:

     sed 's/^\(.\{5\}\).\(.*\)/\1\2/' file
     sed 's/^\(.\{6\}\).\(.*\)/\1\2/' file

Thanks a lot in advance,

Kat

You could try stringing them all together with semi-colons?

sed "s/.../.../g;s/.../.../" file

Basically you have three options:

1) Use the semi-colon separator:

sed 'command1;command2;...;commandn' input_file

2) Use the "-e" option:

sed -e 'command1' -e 'command2' ... -e 'commandn' input_file

3) Use the file command option:

sed -f Sed_File input_file

Where "Sed_File" will look like this:

command1
command2
...
commandn
1 Like

Thanks a lot! I will try those out :slight_smile: