0

I have a bash file, in which I would like to make several changes.

sed -i 's/      /    /g' testfile
sed -i -e 's/#[a-z]$//' -e '/^$/d' testfile
sed -i 's/ *$//' testfile
sed '/##=/ r header' testfile

In first command would like to replace TAB with spaces and after that remove comments(there are also comments, which begin with ##) and empty lines. After that would like to insert a file after a specified pattern in my file. Is there something wrong with command ordering?

  • 4
    The commands "work", but without a sample testfile, there are no quirks of ordering to comment on. – Thomas Dickey Jun 21 '16 at 23:58
1

you can give multiple instruction in one shot of sed, for example:

sed 's/\t/    /g;/^ *$/d;s/^#/NODIESE/' testfile

this single line

  1. replace tab with space
  2. delete line that start with empty stuff (or empty line)
  3. replace Dash at start with the word NODIESE

so your test file is processed only once and you launch sed only one time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.