Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

removing name in pathname

SOLVED
Go to solution
Henry Chua
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


7 REPLIES
Isralyn Manalac_1
Regular Advisor
Solution

Re: removing name in pathname

Hi Henry,

Use vi, then execute:

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

regards,

Isralyn
Henry Chua
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
Amit Agarwal_1
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 '/'.

Muthukumar_5
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!
Isralyn Manalac_1
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
Biswajit Tripathy
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
Henry Chua
Super Advisor

Re: removing name in pathname

Thanks guys found the answer I wanted..