Advertisement

05.24.2008 at 07:54PM PDT, ID: 23430885
[x]
Attachment Details

Using sed command in a bash script to replace '../../'

Asked by Simon336697 in Red Hat Linux, Linux, Linux Administration

Hi guys!
Im a newbie to using sed and would love your help.
What Im trying to do is the following...........

I have a folder that contain multiple filenames that have the following naming convention..

*menu4_it_sware_videogalleries_*.php

In these files above, there are multiple instances of teh following string..

../../

The above I wish to change all instances of '../../' to nothing.

The problem Im having is that when Im using the following bash script to do this, the resultant file is totally BLANK, replacing everything with nothing.

Because I wish to replace the backslashes, I thought I had to use an '@' symbol as the delimiter, and not the standard backslash, but this doesnt seem to work.
If i use the below script and test just replacing text other than the backslash character, and change the deliimiters from @ to a '/', the script works.

Any help greatly appreciated.

Here is the script.......

========================================== sed_replace.sh:
      1 #! /bin/bash
      2 for text in *menu4_it_sware_videogalleries_*.php; do
      3 mv $text $text.old
      4 sed 's@../../@@g' $text.old > $text
      5 rm -f $text.old
      6 done
=============================================
Start Free Trial
 
Loading Advertisement...
 
[+][-]05.24.2008 at 08:05PM PDT, ID: 21641257

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Red Hat Linux, Linux, Linux Administration
Sign Up Now!
Solution Provided By: omarfarid
Participating Experts: 2
Solution Grade: A
 
 
[+][-]05.24.2008 at 08:10PM PDT, ID: 21641296

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.24.2008 at 08:14PM PDT, ID: 21641323

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.24.2008 at 08:15PM PDT, ID: 21641326

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.24.2008 at 08:16PM PDT, ID: 21641328

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.24.2008 at 08:19PM PDT, ID: 21641333

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.24.2008 at 08:20PM PDT, ID: 21641337

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.24.2008 at 08:22PM PDT, ID: 21641342

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.24.2008 at 08:22PM PDT, ID: 21641346

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628