Unix Shell - sed idea

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > January 2006 > sed idea





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author sed idea
Dirk Laurenz

2006-01-19, 8:11 am

Hi,

i hava file like this:

AGESPF01:192.168.89.31:/samba/agespf01
AGESPF02:192.168.89.32:/samba/agespf02:/samba/agespf02/data/profiles01
AGESPF03:192.168.89.33:/samba/agespf03:/samba/agespf03/data/profiles01

I want to search for s/^AGESPF02/ and add at the end of
that line ':/samba/agespf02/data/profiles02'.

Afterwards the file must look like this:
AGESPF01:192.168.89.31:/samba/agespf01
AGESPF02:192.168.89.32:/samba/agespf02:/samba/agespf02/data/profiles01:/samba/agespf02/data/profiles02
AGESPF03:192.168.89.33:/samba/agespf03:/samba/agespf03/data/profiles01

How can i do this?


Barry Margolin

2006-01-19, 8:11 am

In article <dqnl1v$8ch$1@nntp.fujitsu-siemens.com>,
Dirk Laurenz <dirk.laurenz@fujitsu-siemens.com> wrote:

> Hi,
>
> i hava file like this:
>
> AGESPF01:192.168.89.31:/samba/agespf01
> AGESPF02:192.168.89.32:/samba/agespf02:/samba/agespf02/data/profiles01
> AGESPF03:192.168.89.33:/samba/agespf03:/samba/agespf03/data/profiles01
>
> I want to search for s/^AGESPF02/ and add at the end of
> that line ':/samba/agespf02/data/profiles02'.
>
> Afterwards the file must look like this:
> AGESPF01:192.168.89.31:/samba/agespf01
> AGESPF02:192.168.89.32:/samba/agespf02:/samba/agespf02/data/profiles01:/samba/
> agespf02/data/profiles02
> AGESPF03:192.168.89.33:/samba/agespf03:/samba/agespf03/data/profiles01
>
> How can i do this?


sed '/^AGESPF02/s|$|:/samba/agespf02/data/profiles02|' infile > outfile

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
Dirk Laurenz

2006-01-19, 8:11 am

Hi,

Barry Margolin schrieb:
> In article <dqnl1v$8ch$1@nntp.fujitsu-siemens.com>,
>
> sed '/^AGESPF02/s|$|:/samba/agespf02/data/profiles02|' infile > outfile
>

Can u explain a lil bit?

Dirk
Bruce Barnett

2006-01-19, 6:24 pm

Dirk Laurenz <dirk.laurenz@fujitsu-siemens.com> writes:

> Barry Margolin schrieb:
> Can u explain a lil bit?



/^AGESPF02/
- searches for all lines that start with AGESPF02
once you have such a line, then...
s|$|:/samba/agespf02/data/profiles02|
Substitute from '$' (which means the end of the line)
to '/samba/agespf02/data/profiles02'

The | is used instead of / because (1) you can, and (2) it doesn't get
confused with the / in /samba/agespf02/data/profiles02

--
Sending unsolicited commercial e-mail to this account incurs a fee of
$500 per message, and acknowledges the legality of this contract.
Tweedale

2006-01-19, 6:24 pm

On 19 Jan 2006 at 9:23, Dirk Laurenz wrote:
> Hi,
>
> Barry Margolin schrieb:
> Can u explain a lil bit?


Which part of the sed manpage is causing you confusion?


--
email: echo twa@pj.hj.br | tr a-gh-pq-z t-za-ij-s
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com