Operating System - HP-UX
1849053 Members
6266 Online
104041 Solutions
New Discussion

Re: deleting a string and string substitution

 
SOLVED
Go to solution
Jimmy Roux_1
Advisor

deleting a string and string substitution

Hello,

First question:
A file has the following in several lines

/var/tmp/logs/C/dat

sed 's/logs//g' replaces 'logs' with '/' which is not what I want. What I want is to remove logs so that I end up with a directory structure of /var/tmp/C/dat withing the file.
How would you do it using sed? perl? others?

Second question:
A file has several "core" lines, how would you substitute "hostname:/tmp/apps/XYZ" using sed? perl? others?

Thanks,

Jimmy
3 REPLIES 3
Sundar_7
Honored Contributor

Re: deleting a string and string substitution

Hi Jimmy,

Try this.

sed 's/logs\///g' oldfile > newfile.

Sundar.
Learn What to do ,How to do and more importantly When to do ?
Sridhar Bhaskarla
Honored Contributor
Solution

Re: deleting a string and string substitution

Hi Jimmy,

You would need to remove the entire string '/logs' or 'logs/'

sed 's/\/logs//g'

I would do something like this to replace core file if I understand your second question correctly

HOST=$(hostname)

sed 's/core/'$HOST'\:\/tmp\/apps\/XYZ/g'

sed has it's own limitations though.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Victor Fridyev
Honored Contributor

Re: deleting a string and string substitution

Hi
A possible solution for your first question may be something like this:
sed 's?/logs??'

Could you please clarify you second question ? You want to substitute
hostname:/tmp/apps/XYZ with what ?
Entities are not to be multiplied beyond necessity - RTFM