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 > Need to delete the next line in a file
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Need to delete the next line in a file

Réponse
 
LinkBack Outils de la discussion
Vieux 17/08/2006, 17h39   #1
heynetboy
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Need to delete the next line in a file

Hello -

I need to find a line in a file that starts with a % and then delete
the very next line leaving the line that starts with the %. I can find
the line by using ^% but no idea how the delete the next line.

Any ideas how to do this?

HNB

  Réponse avec citation
Vieux 17/08/2006, 17h55   #2
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need to delete the next line in a file

On 2006-08-17, heynetboy wrote:
> Hello -
>
> I need to find a line in a file that starts with a % and then delete
> the very next line leaving the line that starts with the %. I can find
> the line by using ^% but no idea how the delete the next line.


awk 'n != 1 { print $0 }
{ n = 0 }
/^%/ { n = 1 }
'

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
  Réponse avec citation
Vieux 17/08/2006, 18h18   #3
Xicheng Jia
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need to delete the next line in a file

heynetboy wrote:
> Hello -
>
> I need to find a line in a file that starts with a % and then delete
> the very next line leaving the line that starts with the %. I can find
> the line by using ^% but no idea how the delete the next line.
>
> Any ideas how to do this?
>
> HNB


if there is no adjacent lines starting with '%'
then
perl -pe '<> if /^%/'
sed '/^%/N;s/\n[^\n]*$//'
awk '/^%/{print;getline;next}1'
else
redefine the rule

Xicheng

  Réponse avec citation
Vieux 17/08/2006, 18h28   #4
Pawel Gancarz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need to delete the next line in a file

heynetboy wrote:
> I need to find a line in a file that starts with a % and then delete
> the very next line leaving the line that starts with the %. I can find
> the line by using ^% but no idea how the delete the next line.
> Any ideas how to do this?


sed '/^%/{n;d}'
--
pgancarz, at, o2, pl
  Réponse avec citation
Vieux 17/08/2006, 19h07   #5
Bill Marcum
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need to delete the next line in a file

On 17 Aug 2006 09:39:54 -0700, heynetboy
<heynetboy@gmail.com> wrote:
> Hello -
>
> I need to find a line in a file that starts with a % and then delete
> the very next line leaving the line that starts with the %. I can find
> the line by using ^% but no idea how the delete the next line.
>
> Any ideas how to do this?
>
> HNB
>

awk '{print} /^%/{getline}'

What if two or more consecutive lines begin with %?

--
Graduate students and most professors are no smarter than undergrads.
They're just older.
  Réponse avec citation
Vieux 17/08/2006, 19h36   #6
heynetboy
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need to delete the next line in a file


heynetboy wrote:
> Hello -
>
> I need to find a line in a file that starts with a % and then delete
> the very next line leaving the line that starts with the %. I can find
> the line by using ^% but no idea how the delete the next line.
>
> Any ideas how to do this?


WOW - what great response. The last one

sed '/^%/{n;d;}'

was the shortest and easiest to understand (I don't know AWK or PERL
very well). I just had to add the last ";" to make the single line
command work

Thanks everyone!

HNB

  Réponse avec citation
Vieux 17/08/2006, 19h42   #7
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need to delete the next line in a file

2006-08-17, 17:28(+00), Pawel Gancarz:
> heynetboy wrote:
>> I need to find a line in a file that starts with a % and then delete
>> the very next line leaving the line that starts with the %. I can find
>> the line by using ^% but no idea how the delete the next line.
>> Any ideas how to do this?

>
> sed '/^%/{n;d}'


sed '/^%/{n;d;}'

--
Stéphane
  Réponse avec citation
Vieux 17/08/2006, 22h53   #8
Pawel Gancarz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need to delete the next line in a file

Stephane CHAZELAS wrote:
> sed '/^%/{n;d;}'


Sure, thanks.
--
pgancarz, at, o2, pl
  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 23h03.


É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,11368 seconds with 16 queries