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

Sed reqular expression question.

Réponse
 
LinkBack Outils de la discussion
Vieux 30/10/2007, 21h48   #1
mostro713@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Sed reqular expression question.

Hi.

I have a list of IP addresses (one per line) in a text file. I need
to surround them with pipe symbols and include a single space in
between the first and last number.

For example:

[before]
192.168.1.1
<space>
192.168.1.2
192.168.1.3
<space>
192.168.1.4
192.168.1.5

[after]
| 192.168.1.1 |
| 192.168.1.2 |
| 192.168.1.3 |
| 192.168.1.4 |
| 192.168.1.5 |

I tried a few different sed line that didn't work out so well

Thanks in advance....

  Réponse avec citation
Vieux 30/10/2007, 21h56   #2
Christian Schneider
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Sed reqular expression question.

Thus spake mostro713@gmail.com (mostro713@gmail.com):
> I have a list of IP addresses (one per line) in a text file. I need
> to surround them with pipe symbols and include a single space in
> between the first and last number.
>
> For example:
>
> [before]
> 192.168.1.1
> <space>
> 192.168.1.2
> 192.168.1.3
> <space>
> 192.168.1.4
> 192.168.1.5
>
> [after]
>| 192.168.1.1 |
>| 192.168.1.2 |
>| 192.168.1.3 |
>| 192.168.1.4 |
>| 192.168.1.5 |
>
> I tried a few different sed line that didn't work out so well


Means "<space>" a empty line? If so use
sed '/^$/d;s/^/| /;s/$/ |/' file
Otherwise use
sed 's/^/| /;s/$/ |/' file
--
{ \|/ ______ \|/ Access denieded | Christian 'strcat' Schneider }
{ "@' / , . \ `@" Nah Nah Nah :p | http://www.strcat.de/ }
{ /__| \____/ |__\ | GnuPG-Key-ID: 47E322CE }
{ \___U__/ | http://strcat.de/chris.gpg }
  Réponse avec citation
Vieux 30/10/2007, 22h10   #3
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Sed reqular expression question.



On 10/30/2007 3:48 PM, mostro713@gmail.com wrote:
> Hi.
>
> I have a list of IP addresses (one per line) in a text file. I need
> to surround them with pipe symbols and include a single space in
> between the first and last number.
>
> For example:
>
> [before]
> 192.168.1.1
> <space>
> 192.168.1.2
> 192.168.1.3
> <space>
> 192.168.1.4
> 192.168.1.5
>
> [after]
> | 192.168.1.1 |
> | 192.168.1.2 |
> | 192.168.1.3 |
> | 192.168.1.4 |
> | 192.168.1.5 |
>
> I tried a few different sed line that didn't work out so well
>
> Thanks in advance....
>


sed 's/\(.*\)/| \1 |/' file

  Réponse avec citation
Vieux 30/10/2007, 22h14   #4
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Sed reqular expression question.

2007-10-30, 21:56(+01), Christian Schneider:
> Thus spake mostro713@gmail.com (mostro713@gmail.com):
>> I have a list of IP addresses (one per line) in a text file. I need
>> to surround them with pipe symbols and include a single space in
>> between the first and last number.
>>
>> For example:
>>
>> [before]
>> 192.168.1.1
>> <space>
>> 192.168.1.2
>> 192.168.1.3
>> <space>
>> 192.168.1.4
>> 192.168.1.5
>>
>> [after]
>>| 192.168.1.1 |
>>| 192.168.1.2 |
>>| 192.168.1.3 |
>>| 192.168.1.4 |
>>| 192.168.1.5 |
>>
>> I tried a few different sed line that didn't work out so well

>
> Means "<space>" a empty line? If so use
> sed '/^$/d;s/^/| /;s/$/ |/' file


Or
sed -n 's/..*/| & |/p' file

> Otherwise use
> sed 's/^/| /;s/$/ |/' file


Or
sed 's/.*/| & |/' file

or

paste -d '| |' - - file - - < /dev/null

--
Stéphane
  Réponse avec citation
Vieux 31/10/2007, 01h41   #5
mostro713@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Sed reqular expression question.

On Oct 30, 4:56 pm, Christian Schneider <str...@gmx.net> wrote:
> Thus spake mostro...@gmail.com (mostro...@gmail.com):
>
>
>
> > I have a list of IP addresses (one per line) in a text file. I need
> > to surround them with pipe symbols and include a single space in
> > between the first and last number.

>
> > For example:

>
> > [before]
> > 192.168.1.1
> > <space>
> > 192.168.1.2
> > 192.168.1.3
> > <space>
> > 192.168.1.4
> > 192.168.1.5

>
> > [after]
> >| 192.168.1.1 |
> >| 192.168.1.2 |
> >| 192.168.1.3 |
> >| 192.168.1.4 |
> >| 192.168.1.5 |

>
> > I tried a few different sed line that didn't work out so well

>
> Means "<space>" a empty line? If so use
> sed '/^$/d;s/^/| /;s/$/ |/' file
> Otherwise use
> sed 's/^/| /;s/$/ |/' file
> --
> { \|/ ______ \|/ Access denieded | Christian 'strcat' Schneider }
> { "@' / , . \ `@" Nah Nah Nah :p | http://www.strcat.de/ }
> { /__| \____/ |__\ | GnuPG-Key-ID: 47E322CE }
> { \___U__/ | http://strcat.de/chris.gpg }




sed '/^$/d;s/^/| /;s/$/ |/' worked for me.. Now I have to read the
man page to figure it out.

Thank you.

  Réponse avec citation
Vieux 31/10/2007, 02h10   #6
Christian Schneider
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Sed reqular expression question.

Thus spake mostro713@gmail.com (mostro713@gmail.com):
> On Oct 30, 4:56 pm, Christian Schneider <str...@gmx.net> wrote:
>> Thus spake mostro...@gmail.com (mostro...@gmail.com):
>>
>> > I have a list of IP addresses (one per line) in a text file. I need
>> > to surround them with pipe symbols and include a single space in
>> > between the first and last number.

[...]
>> Means "<space>" a empty line? If so use
>> sed '/^$/d;s/^/| /;s/$/ |/' file
>> Otherwise use
>> sed 's/^/| /;s/$/ |/' file

[...]
> sed '/^$/d;s/^/| /;s/$/ |/' worked for me.. Now I have to read the
> man page to figure it out.


/^$/d deletes all blank lines from a file. ^ matching the null string at
the beginning of a line and $ the null string at the end of a line. "d"
is "delete".
The semicolon is a "seperator" for the next directive "s/^/| /" which
substitutes ("s") the beginning of each line with "| " ("s/$/ |/" for
the end of each line).
btw. "info sed" is more detailed as the manpage.
--
{ \|/ ______ \|/ Access denieded | Christian 'strcat' Schneider }
{ "@' / , . \ `@" Nah Nah Nah :p | http://www.strcat.de/ }
{ /__| \____/ |__\ | GnuPG-Key-ID: 47E322CE }
{ \___U__/ | http://strcat.de/chris.gpg }
  Réponse avec citation
Vieux 31/10/2007, 10h53   #7
mostro713@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Sed reqular expression question.

On Oct 30, 9:10 pm, Christian Schneider <str...@gmx.net> wrote:
> Thus spake mostro...@gmail.com (mostro...@gmail.com):
>
> > On Oct 30, 4:56 pm, Christian Schneider <str...@gmx.net> wrote:
> >> Thus spake mostro...@gmail.com (mostro...@gmail.com):

>
> >> > I have a list of IP addresses (one per line) in a text file. I need
> >> > to surround them with pipe symbols and include a single space in
> >> > between the first and last number.

> [...]
> >> Means "<space>" a empty line? If so use
> >> sed '/^$/d;s/^/| /;s/$/ |/' file
> >> Otherwise use
> >> sed 's/^/| /;s/$/ |/' file

> [...]
> > sed '/^$/d;s/^/| /;s/$/ |/' worked for me.. Now I have to read the
> > man page to figure it out.

>
> /^$/d deletes all blank lines from a file. ^ matching the null string at
> the beginning of a line and $ the null string at the end of a line. "d"
> is "delete".
> The semicolon is a "seperator" for the next directive "s/^/| /" which
> substitutes ("s") the beginning of each line with "| " ("s/$/ |/" for
> the end of each line).
> btw. "info sed" is more detailed as the manpage.
> --
> { \|/ ______ \|/ Access denieded | Christian 'strcat' Schneider }
> { "@' / , . \ `@" Nah Nah Nah :p | http://www.strcat.de/ }
> { /__| \____/ |__\ | GnuPG-Key-ID: 47E322CE }
> { \___U__/ | http://strcat.de/chris.gpg }


Thanks for the great explanation. Yes, the complete manual is where I
ended up although your paragraphs above is a much better explanation
to an example..


  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 05h31.


É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,16724 seconds with 15 queries