0

I want to delete all spaces between characters after an initial match. An example is

exmpl 0 t h i s a r e t he spaces to d e l e t e
exmpl 1 m o r e spaces to d e l
exmpl 2 o r s m t h completely d i f f e r e n t
exmpl 12 y e t another l i n e

which's output should be:

exmpl 0 thisarethespacestodelete
exmpl 1 morespacestodel
exmpl 2 orsmthcompletelydifferent
exmpl 12 yetanotherline

The spaces between the initial text and the numbers, and the numbers and the following text could also be tabs.

I am able to match the first and second part, e.g., in sed by

sed -i 's/\(exmpl\s*[0-9]*\s*\)\(.*\)/\1\2/'

but I can't figure out to remove all the spaces in \2.

1 Answer 1

3

Using sed:

sed -e 's/ //3g' file

exmpl 0 thisarethespacestodelete
exmpl 1 morespacestodel
exmpl 2 orsmthcompletelydifferent
exmpl 12 yetanotherline

will do replacement from the 3rd match

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .