|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 . |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 . > sed -n '$p;N;s/\n/ / ' file-- Michael Tosch @ hp : com |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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 . >> > > sed -n '$p;N;s/\n/ / ' file> The -n option is often more powerful, but here it works without -n: sed '$p;N;s/\n/ /' file -- Michael Tosch @ hp : com |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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 . 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 |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
Neither of them work.
is there some mistake or something missing |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
parag_paul@hotmail.com wrote:
> Neither of them work. > is there some mistake or something missing > Quoted context is missing; in the first place. |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
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 @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 <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/ / ' < 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 |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
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 <netnews@gclare.org.uk> |
|
![]() |
| Outils de la discussion | |
|
|