Re: sed/awk convert lines to colum
Tim Chase <[email protected]>
| Newsgroups | gmane.editors.sed.user |
|---|---|
| Message-ID | <[email protected]> |
On 12/04/12 07:53, MOKRANI Rachid wrote:
> Many many thanks, it's working. I have an other suggestion.
Just as a point of English, I think you mean "I have another question"
> And if I would like to reduce the number of text (text1 and text2) colums , do you have the magic command ?
>
> id ; text
> 1 ; AAAA
> 1 ; AA BB CC
> 1 ; CC 22 2DS
> 1 ; 45 H DE T
> 2 ; WW NN FDRET
> 2 ; ZZZ DS 05 K
> 2 ; ss sss ss ss ssss
> 3 ; 7584455 tedr dr
> 3 ; JH CD FER GT 544 . 45
> ...
>
> I would like to have with sed/awk the following result
>
> id ; text1 ; text2
> 1 ; AAAA ; AA BB CC (space or other) CC 22 2DS (space or other)45 H DE T
> 2 ; WW NN FDRET ; ZZZ DS 05 K (space or other) ss sss ss ss ssss
> 3 ; 7584455 tedr dr ; JH CD FER GT 544 . 45
Just take my
>> sed -n -e '$!{:a;N;s/^\([0-9]\+\)\(.*\)\n\1\s/\1\2/;$p;ta;P;D;$p;ba}'
And swallow the semicolon too:
sed -n -e '$!{:a;N;s/^\([0-9]\+\)\(.*\)\n\1\s*;/\1\2/;$p;ta;P;D;$p;ba}'
You can put your own punctuation (extra spaces or other delimiters)
after the "\2" if you need.
-tkc