I’ve seen several examples on here of something close to what I’m asking, but not quite.
I have some pipe-delimited flat files which have some extraneous column data that I want to strip out using sed. the basic structure looks like this:
Column1|Column2|Column3|ignore
data1|data2|data3|ignore
data4|data5|data6|ignore
I want an expression using sed that will produce:
Column1|Column2|Column3
data1|data2|data3
data4|data5|data6
This should be stupid easy, but as always regular expressions and sed manage to hurt my brain. I thought this would work:
sed "s/\|ignore//" table1.txt >filtered.txt
but this seems to do nothing. What am I doing wrong?
NOTE: This is GNU sed for Windows.
Don’t escape the pipe.
works on my machine. (GNU sed on Cygwin.)
The idea here is that
\|is the regex pipe, not the literal pipe. I don’t quite know how to figure these things out, but to use(,{, or|in sed regex, you must escape them. But[is not escaped, unless you want the literal character.