How to delete lines starting with certain strings

sed -i '/\[youtube\]/d' /path/to/file

will delete lines, containing "[youtube]".

As one command you can combine patterns like

sed -i '/\[youtube\]\|\[ffmpeg\]\|\[avconv\]/d' /path/to/file

Or right from your command

youtube-dl --extract-audio --audio-quality 0 --newline --audio-format mp3 \
 https://www.youtube.com/playlist?list=PL1C815DB73EC2678E | 
    sed '/\[youtube\]\|\[ffmpeg\]\|\[avconv\]/d' > output.txt

This will write the result to a file output.txt.

If you want to delete lines not just containing [youtube], but starting with [youtube], then add ^ to the pattern, like sed '/^\[youtube\]/d'.

But in your case it does not matter.


I suggest using grep -vE like so:

youtube-dl --extract-audio --audio-quality 0 --newline --audio-format mp3 https://www.youtube.com/playlist?list=PL1C815DB73EC2678E | grep -vE '^\[(youtube|ffmpeg|avconv)\]'

From man grep:

-v, --invert-match
              Invert the sense of matching, to select non-matching lines.  (-v
              is specified by POSIX.)



-E, --extended-regexp
              Interpret  PATTERN  as  an extended regular expression (ERE, see
              below).  (-E is specified by POSIX.)

The -E flag is used to avoid escaping square brackets with slashes. Without -E flag you have to escape the square brackets with a backslash, like so grep -vE '\[youtube\]\|\[ffmpeg\]\|\[avconv\]' Edit:

Since you've requested awk,here's one with awk:

youtube-dl --extract-audio --audio-quality 0 --newline --audio-format mp3 https://www.youtube.com/playlist?list=PL1C815DB73EC2678E | awk '{if ($0~/^\[youtube\]/||/^\[ffmpeg\]/||/^\[avconv\]/||/^WARNING/) next;print}'


Use grep -v as following:

youtube-dl --extract-audio --audio-quality 0 --newline --audio-format mp3 https://www.youtube.com/playlist?list=PL1C815DB73EC2678E | grep -v '^[youtube]' | grep -v '^[ffmpeg]' | grep -v '^[avconv]'