Discussion:
Beginner : delete a line with repeating pattern
v***@yahoo.com
2014-03-04 01:10:50 UTC
Permalink
echo "house boat car, , , ," | sed '/, \{4\}$/d' this works (4 commas in a row)
How do I deal with

echo "house boat car, , , , $" a comma followed by a space 4 times. I tried the [ ] but it didnt work
echo "house boat car, , , ," | sed '/[, ]\{4\}$/d'
echo "house boat car, , , , " | sed '/, \{4\}$/d'

Thanks !!
Tim Chase
2014-03-04 01:40:06 UTC
Permalink
Post by v***@yahoo.com
echo "house boat car, , , ," | sed '/, \{4\}$/d' this works (4
commas in a row)
I don't think that this does what you expect it to. It doesn't find 4 commas in a row, if finds a comma followed by 4 spaces at the end of the line, and deletes the whole row if it finds that.
Post by v***@yahoo.com
How do I deal with
echo "house boat car, , , , $" a comma followed by a space 4 times. I tried the [ ] but it didnt work
echo "house boat car, , , ," | sed '/[, ]\{4\}$/d'
echo "house boat car, , , , " | sed '/, \{4\}$/d'
I *think* what you want is 4 "comma + zero or more spaces" which
should be something like

echo "house boat car, , , , " | sed '/\(, *\)\{4\}$/d'

If you just want to remove the commas/spaces while keeping the first
value, you can do

echo "house boat car, , , , " | sed 's/\(, *\)\{4\}$//'

-tim

Loading...