Skip to main content
missing ; for portability, removed UUOC, -e not needed as there's only one expression. That usage of `-i` is GNU specific. Mention -i.back for backups.
Source Link
Stéphane Chazelas
  • 584.6k
  • 96
  • 1.1k
  • 1.7k

sed is a great tool for that:

                           # substitute ("s/")
sed -e 's/^[[:blank:]]*// ; # parts of lines that start ("^")  with a space/tab 
        s/[[:blank:]]*$//' # or end ("$") with a space/tab
                           # with nothing (/)

You can use it for your case be either piping in the text, e.g.

cat file |<file sed -e 's/^{{^[[...

or by acting on it 'inline' if your -sed is the GNU one:

sed -i 's/...' file

but changing the source this way is "dangerous" as it may be unrecoverable when it doesn't work right (or even when it does!), so backup first (or use -i.bak which also has the benefit to be portable to some BSD seds)!

sed is a great tool for that:

                           # substitute ("s/")
sed -e 's/^[[:blank:]]*//  # parts of lines that start ("^")  with a space/tab 
        s/[[:blank:]]*$//' # or end ("$") with a space/tab
                           # with nothing (/)

You can use it for your case be either piping in the text, e.g.

cat file | sed -e 's/^{{...

or by acting on it 'inline' -

sed -i 's/...' file

but changing the source this way is "dangerous" as it may be unrecoverable when it doesn't work right (or even when it does!), so backup first!

sed is a great tool for that:

                        # substitute ("s/")
sed 's/^[[:blank:]]*//; # parts of lines that start ("^")  with a space/tab 
     s/[[:blank:]]*$//' # or end ("$") with a space/tab
                        # with nothing (/)

You can use it for your case be either piping in the text, e.g.

<file sed -e 's/^[[...

or by acting on it 'inline' if your sed is the GNU one:

sed -i 's/...' file

but changing the source this way is "dangerous" as it may be unrecoverable when it doesn't work right (or even when it does!), so backup first (or use -i.bak which also has the benefit to be portable to some BSD seds)!

added 103 characters in body
Source Link
Michael Durrant
  • 43.7k
  • 72
  • 176
  • 237

sed is a great tool for that:

                           # substitute ("s/")
sed -e 's/^[[:blank:]]*//  # parts of lines that start ("^")  with a space/tab 
        s/[[:blank:]]*$//' # or end ("$") with a space/tab
                           # with nothing (/)

You can use it for your case be either piping in the text, e.g.

cat file | sed -e 's/^{{...

or by acting on it 'inline' -

sed -i 's/...' file

but changing the source this way is "dangerous" as it may be unrecoverable when it doesn't work right (or even when it does!), so backup first!

sed is a great tool for that:

                           # substitute ("s/")
sed -e 's/^[[:blank:]]*//  # parts of lines that start ("^")  with a space/tab 
        s/[[:blank:]]*$//' # or end ("$") with a space/tab
                           # with nothing (/)

sed is a great tool for that:

                           # substitute ("s/")
sed -e 's/^[[:blank:]]*//  # parts of lines that start ("^")  with a space/tab 
        s/[[:blank:]]*$//' # or end ("$") with a space/tab
                           # with nothing (/)

You can use it for your case be either piping in the text, e.g.

cat file | sed -e 's/^{{...

or by acting on it 'inline' -

sed -i 's/...' file

but changing the source this way is "dangerous" as it may be unrecoverable when it doesn't work right (or even when it does!), so backup first!

added 103 characters in body
Source Link
Michael Durrant
  • 43.7k
  • 72
  • 176
  • 237

sed is a great tool for that:

                           # substitute ("s/")
sed -e 's/^[[:blank:]]*//  # Linesparts of lines that start ("^")  with a space/tab 
        s/[[:blank:]]*$//' # lines thator end ("$") with a space/tab
                           # with nothing (/)

sed is a great tool for that:

sed -e 's/^[[:blank:]]*//  # Lines that start ("^")  with a space/tab 
        s/[[:blank:]]*$//' # lines that end ("$") with a space/tab

sed is a great tool for that:

                           # substitute ("s/")
sed -e 's/^[[:blank:]]*//  # parts of lines that start ("^")  with a space/tab 
        s/[[:blank:]]*$//' # or end ("$") with a space/tab
                           # with nothing (/)
Source Link
Michael Durrant
  • 43.7k
  • 72
  • 176
  • 237
Loading