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.

Recently, I look for scripts to take this:

This;
Is;
First;
Line;

and make it like:

This Is First Line
share|improve this question
1  
Do you want to put everything on a single line? If not, when does the second line start? –  Gilles Mar 8 '12 at 18:28

2 Answers 2

Neither awk nor sed, but how about tr instead:

printf 'This;\nIs;\nFirst;\nLine;\n' | 
    tr -s ';[:space:]' '[ *]'

Output: This is First Line

share|improve this answer
    
Sorry, I have tried this commands but the result is not my wanted. In fact, the file containts more records like: –  Alan Fok Mar 8 '12 at 3:42
3  
@AlanFok You should put what you want in the question if you want people to be able to help you. –  jw013 Mar 8 '12 at 4:04
    
In fact, the file contains more data and have to convert into columns as CSV file. –  Alan Fok Mar 8 '12 at 4:20
1  
@AlanFok What I meant was that the question that you posted has been answered. If that's not what you really wanted to ask, update the question. Don't expect people to read your mind or know what your system looks like. –  jw013 Mar 8 '12 at 4:56
1  
@manatwork Thanks. The * is kept in for maximum portability. –  jw013 Mar 8 '12 at 20:33

Your example shows spaces between fields, but you mention "CSV", which means Comma Seperated Values... I've used spaces. Just change / / to /,/ if you want commas.

Input file contains:

This;
Is;
First;
Line;
This;
Is;
Second;
Line;

The script:

 sed -nr 'N; N; N; s/;\n/ /g; s/;$//p' file

Output:

This Is First Line
This Is Second Line
share|improve this answer

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.