Solved

SED Help

Posted on 2012-03-23
6
439 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

A short article about problems I had with the new location API and permissions in Marshmallow
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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…

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now