Can you do the following

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 .
parag_paul [ Mi, 31 Oktober 2007 23:33 ] [ ID #1858242 ]

Re: Can you do the following

parag_paul [at] 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 [at] hp : com
Michael Tosch [ Do, 01 November 2007 00:03 ] [ ID #1858243 ]

Re: Can you do the following

Michael Tosch wrote:
> parag_paul [at] 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 [at] hp : com
Michael Tosch [ Do, 01 November 2007 00:06 ] [ ID #1859580 ]

Re: Can you do the following

2007-10-31, 15:33(-07), parag_paul [at] 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
Stephane CHAZELAS [ Do, 01 November 2007 00:09 ] [ ID #1859581 ]

Re: Can you do the following

Neither of them work.
is there some mistake or something missing
parag_paul [ Do, 01 November 2007 02:49 ] [ ID #1859588 ]

Re: Can you do the following

parag_paul [at] hotmail.com wrote:
> Neither of them work.
> is there some mistake or something missing
>

Quoted context is missing; in the first place.
Janis Papanagnou [ Do, 01 November 2007 03:18 ] [ ID #1859590 ]

Re: Can you do the following

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 <esc>
means the single Escape key, of course)
OJj<esc>0"mD

#-- then position your cursor on the first line of the data you want
to "pair up", then press
[at] m
#-- if that works to your satisfaction, then try holding down the [at]
key for five seconds or so...


#------------------ You may also try this:

xargs -L 2 echo <orig.txt>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
Jstein [ Do, 01 November 2007 06:24 ] [ ID #1859594 ]

Re: Can you do the following

parag_paul [at] 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 <netnews [at] gclare.org.uk>
Geoff Clare [ Do, 01 November 2007 14:51 ] [ ID #1859600 ]

Re: Can you do the following

Geoff Clare wrote:
> parag_paul [at] 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
Janis Papanagnou [ Do, 01 November 2007 15:16 ] [ ID #1859601 ]

Re: Can you do the following

> > parag_p... [at] 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
parag_paul [ Do, 01 November 2007 19:57 ] [ ID #1859613 ]
Linux » comp.unix.shell » Can you do the following

Vorheriges Thema: I18N Shell Scripts (gettext)
Nächstes Thema: Removing a letter from a command's first argument