Solved

SED Help

Posted on 2012-03-23
6
450 Views
Last Modified: 2013-11-13
Hi all,

I am currently writing a command that allows me to appending a '#' in line of a text to help me disable a script (main.sh) from calling a sub-script (test.sh)

I have managed to get it working like this:

sed -i 's:./test.sh:#./test.sh:g' main.sh

Open in new window


however i need to have another script to have the '#' removed to re-enable the call.

and it works like this:

sed -i 's:#./test.sh:./test.sh:g' main.sh

Open in new window


it works ok assuming that the first command is only run once, however should it be run multiple times (in this case 4 times), this is the output:

####test.sh

as a result the second script needs to be run 4 times in to remove all instances of '#'.

How should i approach this?

 Should i fix the first script to ensure only one # is allowed to be appended prior to test.sh? or
should i fix the second script to ensure all instances of '#' are removed before test.sh?

appreciate any help as i am still relatively new to SED.

Thanks!
0
Comment
Question by:jaglin84
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 134 total points
ID: 37756210
sed -i 's:#*./test.sh:./test.sh:g' main.sh
0
 
LVL 84

Assisted Solution

by:ozo
ozo earned 134 total points
ID: 37756217
or
sed -i 's:#*./test.sh:#./test.sh:g' main.sh
0
 

Expert Comment

by:TheDoug
ID: 37783570
Sed uses regular expressions in its syntax, so you only need to add a * after a char to consider it multiple times
0
 
LVL 19

Assisted Solution

by:simon3270
simon3270 earned 66 total points
ID: 37828318
Alternatively, fix the problem in the "comment out" script - use this (assuming that the "." of "./test.sh" is in the first column of the file):
sed -i 's:^./test.sh:#./test.sh:g' main.sh

Open in new window

0
 
LVL 53

Expert Comment

by:Dhaest
ID: 38249566
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A short article about a problem I had getting the GPS LocationListener working.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question