Quote:
Originally Posted by jawsnnn
Here is the problem:
I have a file with some strings separated by spaces, and with delimiters, e.g.
1 2 3 4 5 ~1 2 3 4 5 ~
1 2 3 4 5 ~1 2 3 4 5 ~
1 2 3 4 5 ~1 2 3 4 5 ~
I want to replace the spaces between the field and the delimiters to some character (@ in this example)
1 2 3 4 5@@@@~1 2 3 4 5@@@~
1 2 3 4 5@@@@~1 2 3 4 5@@@~
1 2 3 4 5@@@@~1 2 3 4 5@@@~
The regexes I have tried so far are obviously wrong:
sed 's/[ ]*~/@/g' # will replace all spaces with a single @
sed 's/[ ]/@/g' # will replace all spaces, even those within data with a # single @
Any ideas?
|
Hi,
please use code-tags in the future so that we can see how many spaces there are in the sample data.
As for your problem, try this:
Code:
sed -r ':a s/ (@*~)/@\1/g;ta' file
Requires GNU sed.