Multiple patterns in SED delete

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 1K views
swartzism
Messages
103
Reaction score
0
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?
 
Physics news on Phys.org
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:
egrep -v '(^$|^   |^ |^=|^/)' somefile > newfile

You can also use POSIX character classes like
Code:
^[:space:]
to get either \t or ' ' (space).
 
swartzism said:
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?
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.