Can you do the following
am 31.10.2007 23:33:45 von parag_paul
In Vi can you merge every two lines
like
i
have
to
go
to
the
market
becomes
i have
to go
to the
market
Here, I think subsitituing the end of the statement with carriage
return should help .
Re: Can you do the following
am 01.11.2007 00:03:52 von Michael Tosch
parag_paul@hotmail.com wrote:
> In Vi can you merge every two lines
>
>
> like
>
>
> i
> have
> to
> go
> to
> the
> market
>
> becomes
>
> i have
> to go
> to the
> market
>
>
> Here, I think subsitituing the end of the statement with carriage
> return should help .
>
sed -n '$p;N;s/\n/ /;p' file
--
Michael Tosch @ hp : com
Re: Can you do the following
am 01.11.2007 00:06:03 von Michael Tosch
Michael Tosch wrote:
> parag_paul@hotmail.com wrote:
>> In Vi can you merge every two lines
>>
>>
>> like
>>
>>
>> i
>> have
>> to
>> go
>> to
>> the
>> market
>>
>> becomes
>>
>> i have
>> to go
>> to the
>> market
>>
>>
>> Here, I think subsitituing the end of the statement with carriage
>> return should help .
>>
>
> sed -n '$p;N;s/\n/ /;p' file
>
The -n option is often more powerful, but here it works without -n:
sed '$p;N;s/\n/ /' file
--
Michael Tosch @ hp : com
Re: Can you do the following
am 01.11.2007 00:09:18 von Stephane CHAZELAS
2007-10-31, 15:33(-07), parag_paul@hotmail.com:
> In Vi can you merge every two lines
>
> like
>
> i
> have
> to
> go
> to
> the
> market
>
> becomes
>
> i have
> to go
> to the
> market
>
>
> Here, I think subsitituing the end of the statement with carriage
> return should help .
With vim:
%s/\n\(.*\n\)/ \1/
With vi:
:%!paste -sd ' \n' -
or
:%!paste -d ' ' - -
(that one might add a trailing " " on the last line).
Note that there's a newgroup to discuss about vi: comp.editors.
--
Stéphane
Re: Can you do the following
am 01.11.2007 02:49:03 von parag_paul
Neither of them work.
is there some mistake or something missing
Re: Can you do the following
am 01.11.2007 03:18:32 von Janis Papanagnou
parag_paul@hotmail.com wrote:
> Neither of them work.
> is there some mistake or something missing
>
Quoted context is missing; in the first place.
Re: Can you do the following
am 01.11.2007 06:24:29 von Jstein
Michael is correct, you can use "sed" and it will work.
Other options:
#-- define a "vi" macro to do it for you.
#-- press the following keys exactly, case sensitive (except
means the single Escape key, of course)
OJj0"mD
#-- then position your cursor on the first line of the data you want
to "pair up", then press
@m
#-- if that works to your satisfaction, then try holding down the @
key for five seconds or so...
#------------------ You may also try this:
xargs -L 2 echo new.txt
or if you are in "vi" already goto the top of the file, and type:
!G xargs -L 2 echo
#------------------ You may also try this:
#-- this will put your data in two wide columns, evenly spaced
pr -2 -t
#-------- or even a 'quicky' shell script fragment, like
while { read ONE; read TWO ; } ;do
echo $ONE $TWO
done < orig.txt > new.txt
#------- Though Michael's solution should also work, of
sed -n '$p;N;s/\n/ /;p' < old.txt > new.txt
#-------- even a goofy little awk script, like
awk '{if(two != "") {print one, two; one="";two=""} else { two=one;
one=$0 } }' < old.txt > new.txt
Re: Can you do the following
am 01.11.2007 14:51:11 von Geoff Clare
parag_paul@hotmail.com wrote:
> In Vi can you merge every two lines
>
>
> like
>
>
> i
> have
> to
> go
> to
> the
> market
>
> becomes
>
> i have
> to go
> to the
> market
:g/^/,+j
With an odd number of lines there will be an error message, but you
can just ignore it.
--
Geoff Clare
Re: Can you do the following
am 01.11.2007 15:16:07 von Janis Papanagnou
Geoff Clare wrote:
> parag_paul@hotmail.com wrote:
>
>
>>In Vi can you merge every two lines
>>
>>
>>like
>>
>>
>>i
>>have
>>to
>>go
>>to
>>the
>>market
>>
>>becomes
>>
>>i have
>>to go
>>to the
>>market
>
>
> :g/^/,+j
>
> With an odd number of lines there will be an error message, but you
> can just ignore it.
>
With vim (no vi available to check) you can avoid the error message by
:1,$-1g/^/,+j
which seems to work with even and odd number of lines.
Janis
Re: Can you do the following
am 01.11.2007 19:57:26 von parag_paul
> > parag_p...@hotmail.com wrote:
>
> >>In Vi can you merge every two lines
>
> >>like
>
> >>i
> >>have
> >>to
> >>go
> >>to
> >>the
> >>market
>
> >>becomes
>
> >>i have
> >>to go
> >>to the
> >>market
>
> > :g/^/,+j
>
> > With an odd number of lines there will be an error message, but you
> > can just ignore it.
>
> With vim (no vi available to check) you can avoid the error message by
>
> :1,$-1g/^/,+j
>
> which seems to work with even and odd number of lines.
>
Thanks guys , these last ones help. Sed was not my intention.
Ok thank you