PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > Can you do the following
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Can you do the following

Réponse
 
LinkBack Outils de la discussion
Vieux 31/10/2007, 23h33   #1
parag_paul@hotmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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 .

  Réponse avec citation
Vieux 01/11/2007, 00h03   #2
Michael Tosch
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Can you do the following

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
  Réponse avec citation
Vieux 01/11/2007, 00h06   #3
Michael Tosch
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Can you do the following

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
  Réponse avec citation
Vieux 01/11/2007, 00h09   #4
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Can you do the following

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
  Réponse avec citation
Vieux 01/11/2007, 02h49   #5
parag_paul@hotmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Can you do the following

Neither of them work.
is there some mistake or something missing

  Réponse avec citation
Vieux 01/11/2007, 03h18   #6
Janis Papanagnou
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Can you do the following

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


Quoted context is missing; in the first place.
  Réponse avec citation
Vieux 01/11/2007, 06h24   #7
Jstein
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
@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


  Réponse avec citation
Vieux 01/11/2007, 14h51   #8
Geoff Clare
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Can you do the following

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>
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 09h38.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,14979 seconds with 16 queries