Solved

SED Help

Posted on 2012-03-23
6
436 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
Comment Utility
sed -i 's:#*./test.sh:./test.sh:g' main.sh
0
 
LVL 84

Assisted Solution

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

Expert Comment

by:TheDoug
Comment Utility
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
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This article will show, step by step, how to integrate R code into a R Sweave document
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

744 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

18 Experts available now in Live!

Get 1:1 Help Now