|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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.... |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 } |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
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 } |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
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.. |
|
![]() |
| Outils de la discussion | |
|
|