0

Recently, I look for scripts to take this:

This;
Is;
First;
Line;

and make it like:

This Is First Line
1
  • 1
    Do you want to put everything on a single line? If not, when does the second line start? Mar 8, 2012 at 18:28

2 Answers 2

1

Neither awk nor sed, but how about tr instead:

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

Output: This is First Line

7
  • 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, 2012 at 3:42
  • 4
    @AlanFok You should put what you want in the question if you want people to be able to help you.
    – jw013
    Mar 8, 2012 at 4:04
  • In fact, the file contains more data and have to convert into columns as CSV file.
    – Alan Fok
    Mar 8, 2012 at 4:20
  • 2
    @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, 2012 at 4:56
  • 1
    @manatwork Thanks. The * is kept in for maximum portability.
    – jw013
    Mar 8, 2012 at 20:33
0

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

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