Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a file with the following format:

aaa@ bbb
bbb@ ccc& ddddd@ aaaf
ccc@ ddd& eee: abcd& dassda

The output should be:

aaaa@ bbb
bbb@ ccc&
ddddd@ aaaf
ccc@ ddd&
eee@ abcd& dassda

How would I be able to achieve this using AWK? I've tried sed and awk but I can only print a new line after the delimeter, I don't know how to print the whole thing on the next line.

share|improve this question

1 Answer 1

sed :

sed 's/& /\&\n/' file

in case you need replace all & on the each string just add g after last /.

awk :

awk '{ sub(/& /,"&\n"); print }'

in case you need replace all & on the each string use gsub instead sub.

share|improve this answer
    
can you explain how awk way works? –  Speakus May 8 at 7:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.