[NTLUG:Discuss] scripting question

Wayne Walker wwalker at solid-constructs.com
Wed Apr 20 14:25:20 CDT 2011


On Wed, Apr 20, 2011 at 02:06:26PM -0500, Fred James wrote:
> Monty Shinn wrote:
> >Greetings.
> >
> >I am trying to delete part of a line that is actually a directory
> >path in a file with multiple lines.
> >
> >The paths in the file looks like this:
> >
> >/usr/test/working/access/hbr/filename.plist.
> >/usr/test/working/access/mbr/filename.plist.
> >/usr/test/working/access/lbr/filename.plist.
> >
> >I am wanting the paths in the file to end up like this:
> >
> >access/hbr/filename.plist
> >access/mbr/filename.plist
> >access/lbr/filename.plist
> >
> >I have monkeyed around with sed to no avail.  Can't seem to get it
> >to match the pattern I want it to.  I was able to get grep to see
> >the pattern using grep -E, but can't figure out how to do anything
> >with the output.
> >
> >I am trying to do this inside a bash script.
> >
> >Google is just confusing me all the more...
> >
> >Any help would be greatly appreciated.
> >
> >Thanks,
> >
> >Monty
> Monty Shinn
> Did you "escape" (\) the special characters (in this case the /)?
>    s/\/usr\/test\/working\///
> Regards
> Fred James

the s command will allow characters other than /

echo "this is old crap not pig's ears" | sed -e 's/old crap/new stuff/'
echo "this is old crap not pig's ears" | sed -e 's#old crap#new stuff#'
echo "this is old crap not pig's ears" | sed -e 's,old crap,new stuff,'

Therefore:

sed -e 's#/usr/test/working/##' < original > cleaner

Wayne

-- 

Wayne Walker
wwalker at solid-constructs.com
(512) 633-8076
Senior Consultant
Solid Constructs, LLC



More information about the Discuss mailing list