Aaron Perry Aaron Perry - 4 months ago 10
Linux Question

Search for columns ending with certain pattern, then delete that column

I need to search a line of numbers for any columns that end with 999 and then delete that entire column while preserving any leading number (i.e. 8599999.... --> 85)

Data Line:

66 72 79 84 87 90 91 92 92 93 92 91 89 85999999999999999999999999999999999


Desired Output:

66 72 79 84 87 90 91 92 92 93 92 91 89 85

Answer

Using sed

$ echo '66 72 79 84 87 90 91 92 92 93 92 91 89 85999999999999999999999999999999999' | sed 's/999\+//g'
66 72 79 84 87 90 91 92 92 93 92 91 89 85
  • 999\+ 999 followed by any number of consecutive 9s
Comments