Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

removing name in pathname

SOLVED
Go to Solution
Super Advisor

removing name in pathname

Hi Guys

If i have this"
D/DIR1/DIR2/DIR3
D/DIR4/DIR5/DIR6
"

in a log file.. how can I removed the D to make it
"
/DIR1/DIR2/DIR3
/DIR4/DIR5/DIR6"

Best regards
Henry


1 ACCEPTED SOLUTIONS
Regular Advisor Regular Advisor

Re: removing name in pathname

Hi Henry,

Use vi, then execute:

:%s/D\//\//g

regards,

Isralyn
7 REPLIES
Regular Advisor Regular Advisor

Re: removing name in pathname

Hi Henry,

Use vi, then execute:

:%s/D\//\//g

regards,

Isralyn
Super Advisor

Re: removing name in pathname

Hi Isralyn,

I dun quite understand.. what do I have to do..if my log file is named "list".. then what should i do?

regards
Henry
Trusted Contributor Trusted Contributor

Re: removing name in pathname

You can use the sed command.

sed 's/D\//\//g'

Please note the backslash '\' is used to escape the forward slash '/'.

Honored Contributor Honored Contributor

Re: removing name in pathname

You can do as,

sed -i 's/^D//' list

It will remove D in the begin and update it in to list file also.

HTH.
Easy to suggest when don't know about the problem!
Regular Advisor Regular Advisor

Re: removing name in pathname

Hi Henry,

My apologies but upon looking back into the displayed output of the one I posted, it looks confusing. I'll attach it as a word doc. What I suggested is using global string replacement in vi.

Regards,

Isralyn
Honored Contributor Honored Contributor

Re: removing name in pathname

D/DIR1/DIR2/DIR3
D/DIR4/DIR5/DIR6

Correct me if I understand your question
incorrectly. My understanding is, you want to
remove all the chars from the beginning of the line
till the first '/' char. If that's what you want, the
following script should do it:

---
while read -r line
do
echo ${line#*/}
done < /your/logfile
--

- Biswajit
:-)
Highlighted
Super Advisor

Re: removing name in pathname

Thanks guys found the answer I wanted..