Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Multiple patterns in SED delete

  1. Oct 30, 2015 #1
    I would like to delete all lines starting with the following

    - \t (tab)
    - \n (newline)
    - /
    - (single space)
    - =

    I've tried `sed -n '/^\(\t\|\n\|/\| \|=\)$/d' OUTPUT.txt > test.txt` and combos of that to no avail. What am I doing wrong?
  2. jcsd
  3. Oct 30, 2015 #2

    jim mcnamara

    User Avatar

    Staff: Mentor

    Without special syntax sed will not look at \n the way you want. Plus \t will not work. You have to hit the tab key and get what seem to be spaces.
    egrep syntax is easier for me at the moment - but you can use the regex - note that a bunch of spaces is not spaces:
    ^$ is regex for a line that starts with \n, the | symbol is alternation.
    Code (Text):

    egrep -v '(^$|^   |^ |^=|^/)' somefile > newfile
    You can also use POSIX character classes like
    Code (Text):
    to get either \t or ' ' (space).
  4. Oct 31, 2015 #3


    User Avatar

    Staff: Mentor

    Are you wanting to do this in windows or linux? As jim mcnamara indicated, sed is not the best choice; sed brings more problems than you could imagine.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook