|
|
sed question #2 #2
Dear All,
I have a pipeline that generates output like
file1
file2
(basically a list of files separated by newlines - od -c confirms \n
characters).
I want to join them on one line using sed (I know it can be done in a
number of other ways, just want to do it with sed).
I tried sed -e 's/^J//g' but sed came up with the message sed command
garbled (^J is Ctrl-V Ctrl-J to literally insert a newline).
How can I add the newline in the search pattern so that the sed
command will work (SunOS 5.9)?
Regards,
George
|
|
0
|
|
|
|
Reply
|
gklekeas (3)
|
3/27/2012 4:31:48 PM |
|
cityuk <gklekeas@gmail.com> wrote:
> Dear All,
>
> I have a pipeline that generates output like
>
> file1
> file2
>
> (basically a list of files separated by newlines - od -c confirms \n
> characters).
>
> I want to join them on one line using sed (I know it can be done in a
> number of other ways, just want to do it with sed).
>
> I tried sed -e 's/^J//g' but sed came up with the message sed command
> garbled (^J is Ctrl-V Ctrl-J to literally insert a newline).
>
> How can I add the newline in the search pattern so that the sed
> command will work (SunOS 5.9)?
>
> Regards,
> George
I can't fully explain how this work, but I tested it under bsd and solaris:
sed -e :a -e '$!N;s/\n//;ta'
bash-3.00# uname -r
5.10
bash-3.00# cat >> sedtest
line1
line2
line3
line4
bash-3.00# sed -e :a -e '$!N;s/\n//;ta' sedtest
line1line2line3line4
|
|
0
|
|
|
|
Reply
|
presence (537)
|
3/29/2012 5:09:40 AM
|
|
In article <jl0qqj$gla$1@reader1.panix.com>,
Cydrome Leader <presence@MUNGEpanix.com> wrote:
>cityuk <gklekeas@gmail.com> wrote:
>> Dear All,
>>
>> I have a pipeline that generates output like
>>
>> file1
>> file2
>>
>> (basically a list of files separated by newlines - od -c confirms \n
>> characters).
>>
>> I want to join them on one line using sed (I know it can be done in a
>> number of other ways, just want to do it with sed).
>>
>> I tried sed -e 's/^J//g' but sed came up with the message sed command
>> garbled (^J is Ctrl-V Ctrl-J to literally insert a newline).
>>
>> How can I add the newline in the search pattern so that the sed
>> command will work (SunOS 5.9)?
>>
>> Regards,
>> George
>
>I can't fully explain how this work, but I tested it under bsd and solaris:
>
> sed -e :a -e '$!N;s/\n//;ta'
>
>
>
>bash-3.00# uname -r
>5.10
>bash-3.00# cat >> sedtest
>line1
>line2
>line3
>line4
>bash-3.00# sed -e :a -e '$!N;s/\n//;ta' sedtest
>line1line2line3line4
>
>
>
>
In emacs what I do is set fill-column to some huge number
and then do M-q (refill the paragraph -- width is
so wide (fill-column) that whole "paragraph" ends up on one (long) line.
Maybe vim also has such a command, to re "fill" a "paragraph".
And long, long ago I recall running some tool to do that -- was it "fmt",
perhaps?
David
|
|
0
|
|
|
|
Reply
|
dkcombs (290)
|
5/14/2012 2:47:09 AM
|
|
|
2 Replies
146 Views
(page loaded in 0.052 seconds)
|
|
|
|
|
|
|
|
|