Afficher un message
Vieux 30/10/2007, 23h14   #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
 
Page generated in 0,04674 seconds with 9 queries