vendredi 25 avril 2014

Sed Command substitution howw do u treat space or multiple space as one?


Vote count:

0




Quick one. I use this command to insert a line. So if there is a space in the pattern between to entries in the text or file it prints the content on the new line/ . It works fine, however sometime I encounter 2 spaces or 3 spaces instead of one that i'm looking for in the pattern so I get an additional blank lines.



sed "s/ /\n/g"


I want to print a new line only the sed find something in the pattern . How should I use the sed command to treat 1 space or double or triple spaces as one substitute?


Thanks



asked 4 mins ago


1 Answer



Vote count:

2




You need a quantifier:



sed "s/ */\n/g"


or



sed 's/ \+/\n/g'


or



sed -r 's/ +/\n/g'


or



sed 's/ \{1,\}/\n/g'


or



sed -r 's/ {1,}/\n/g'




You could also use tr:



tr -s ' ' '\n'


answered 3 mins ago

devnull

39.8k




Aucun commentaire:

Enregistrer un commentaire