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 > awk question - range selection
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

awk question - range selection

Réponse
 
LinkBack Outils de la discussion
Vieux 06/12/2006, 20h53   #1
banzai
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut awk question - range selection

I have a file with a pattern that repeats throughout the file:

LABEL text text
text text text
text text text
LABEL
more text

(where LABEL is identical throughout the file)

and need to parse it so that it produces everything after each instance of
LABEL (delimited by the next instance of a label) on 1 line :

i.e.

LABEL text text text text text text text text
LABEL more text

etc etc

Thanks in advance





  Réponse avec citation
Vieux 06/12/2006, 21h46   #2
Bill Marcum
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: awk question - range selection

On Wed, 06 Dec 2006 20:53:25 GMT, banzai
<banzai@aa.com> wrote:
> I have a file with a pattern that repeats throughout the file:
>
> LABEL text text
> text text text
> text text text
> LABEL
> more text
>
> (where LABEL is identical throughout the file)
>
> and need to parse it so that it produces everything after each instance of
> LABEL (delimited by the next instance of a label) on 1 line :
>
> i.e.
>
> LABEL text text text text text text text text
> LABEL more text
>
> etc etc
>
> Thanks in advance
>

awk '/^LABEL/{print ""}{printf "%s ",$0} END{print ""}'


--
Don't make a big deal out of everything; just deal with everything.
  Réponse avec citation
Vieux 06/12/2006, 22h56   #3
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: awk question - range selection

banzai wrote:
> I have a file with a pattern that repeats throughout the file:
>
> LABEL text text
> text text text
> text text text
> LABEL
> more text
>
> (where LABEL is identical throughout the file)
>
> and need to parse it so that it produces everything after each instance of
> LABEL (delimited by the next instance of a label)


or by the end of the file apparently

> on 1 line :
>
> i.e.
>
> LABEL text text text text text text text text
> LABEL more text
>


awk -v RS="LABEL" 'NR>1{$1=$1rint RS,$0}' file

Ed.
  Réponse avec citation
Vieux 07/12/2006, 00h40   #4
banzai
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: awk question - range selection


"Bill Marcum" <bmarcum@iglou.com> wrote in message
news:qaqj44-gl3.ln1@don.localnet...
> On Wed, 06 Dec 2006 20:53:25 GMT, banzai
> <banzai@aa.com> wrote:
>> I have a file with a pattern that repeats throughout the file:
>>
>> LABEL text text
>> text text text
>> text text text
>> LABEL
>> more text
>>
>> (where LABEL is identical throughout the file)
>>
>> and need to parse it so that it produces everything after each instance
>> of
>> LABEL (delimited by the next instance of a label) on 1 line :
>>
>> i.e.
>>
>> LABEL text text text text text text text text
>> LABEL more text
>>
>> etc etc
>>
>> Thanks in advance
>>

> awk '/^LABEL/{print ""}{printf "%s ",$0} END{print ""}'
>
>
> --
> Don't make a big deal out of everything; just deal with everything.



thanks


  Réponse avec citation
Vieux 07/12/2006, 00h44   #5
William Park
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: awk question - range selection

banzai <banzai@aa.com> wrote:
> I have a file with a pattern that repeats throughout the file:
>
> LABEL text text
> text text text
> text text text
> LABEL
> more text
>
> (where LABEL is identical throughout the file)
>
> and need to parse it so that it produces everything after each instance of
> LABEL (delimited by the next instance of a label) on 1 line :
>
> i.e.
>
> LABEL text text text text text text text text
> LABEL more text
>
> etc etc
>
> Thanks in advance


1. Put LABEL in its own line, using 'tr', 'sed', whatever

2. Then, you have nice line range to work with. Use 'tr' to collapse
the lines and whitespaces.

If you're adventurous, then you can try my C extensions to Bash.

strcpy all < file
for i in ${all|,LABEL}; do
echo "LABEL ${i|.strip}"
done

See my .sig below.

--
William Park <opengeometry@yahoo.ca>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
http://freshmeat.net/projects/bashdiff/
  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 05h14.


Édité par : vBulletin® version 3.7.3
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 ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12168 seconds with 13 queries