Execute sed altered script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Execute sed altered script
# 1  
Old 02-17-2011
Execute sed altered script

Man...no one answered my last two posts...Oh well, so hey guys i have a script that i'm wanting to put a # on a certain line, and then execute the script but not write it to the script. So far I'm doing it the dirty way with:

Code:
sed -i -e "s/^rm/\#rm/" -e "s/^tar/\#tar/" /path/to/file
                    /path/to/file
                    sed -i -e "s/^\#rm/rm/" -e "s/^\#tar/tar/" /path/to/file

Just seems like there's gotta be a better way. I don't know how to get the changed file to execute. Sed just wants to list it. Help. Thanks
# 2  
Old 02-17-2011
Pipe the output from sed to a shell.
Code:
sed '....' orig-script | ksh

This User Gave Thanks to Perderabo For This Post:
# 3  
Old 02-17-2011
As the file is a shellscript of some kind make the script do the work:
Code:
myscript [switches] args...        # does the rm/tar
myscript -n [switches] args ...    # do not do rm/tar

At the start of the script:
Code:
noop=""

In the getopts section (normally a case statement in a getopts loop):
Code:
n) noop=":" ;;

If you are not using a getopts loop you may change this to suit your program.
Prefix the rm/tar statements with $noop:
Code:
$noop rm ....

The colon acts as a "no-operation" operator. Watch out for side-effects, eg
Code:
${some:=thing}

will be evaluated ($some will be set to thing if null).

Andrew
This User Gave Thanks to apmcd47 For This Post:
# 4  
Old 02-17-2011
definitely using a getopts loop. I think piping this to a shell is the way to go for me. Thanks you guys
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed working on command line but file unchanged when execute with Shell script

I have a simple task to replace unix line feed end of line characters with carriage returns. When I run the following “change file in place” sed instruction from the command line all the Line feeds are successfully replaced with Carriage returns. sed -i 's/$/\r/' lf_file.txt But that same... (1 Reply)
Discussion started by: hawkman2k
1 Replies

2. Shell Programming and Scripting

sed cannot execute [Argument list too long]

Hi All, This question has been asked many times, but my problem is slightly different. In my shell script i am connecting to oracle database and loading the results to .dat file. This .dat file is later used to create to .xls file Some times the size of .dat file becomes more than 120000... (8 Replies)
Discussion started by: galaxy_rocky
8 Replies

3. Shell Programming and Scripting

Using sed to execute multiple commands

Let's say I have a file called test.out. In this file I want to do the following: 1. Search for DIP-10219 and with this: 2. Remove everything in front of cn= 3. Remove everything after *com 4. Remove duplicate lines 5. Replace ( with \( 6. Replace ) with \) For 1-3 I have figured out this... (11 Replies)
Discussion started by: exm
11 Replies

4. AIX

5. what is tunable parameters?can i altered it ?

what is tunable parameters?can i altered it ? (2 Replies)
Discussion started by: ramraj731
2 Replies

5. Programming

CGI Perl script to execute bash script- unable to create folder

Hi I have a bash script which takes parameters sh /tmp/gdg.sh -b BASE-NAME -n 1 -s /source/data -p /dest/data/archive -m ARC gdg.sh will scan the /source/data and will move the contents to /dest/data/archive after passing through some filters. Its working superb from bash I have... (0 Replies)
Discussion started by: rakeshkumar
0 Replies

6. Shell Programming and Scripting

Dos batch script to execute unix shell script

Can anyone help me with a dos batch script to execute a shell script residing in an unix server. I am not able to use ssh. Thanks in advance (2 Replies)
Discussion started by: Shri123
2 Replies

7. Shell Programming and Scripting

Execute unix shell script to text file using the script

Hi all, I am beginner in UNIX...I want to use unix shell script to create text.file...I know how to use using by command...can anybody tell me for the script? Thanks i changed the threads title from "tex file" to "text file", because "tex" would probably be misunderstood as reference to... (4 Replies)
Discussion started by: mastercar
4 Replies

8. Shell Programming and Scripting

Please help: Build a sed command and execute it in a script

I am using an array to store some data (keys e.g 47975081_1215781266128), it can be assumed that it is key to other data. I want extract data from a file based on a couple of keys (range) and store the resulting data in a variable using the following command: sed -n... (9 Replies)
Discussion started by: gugs
9 Replies

9. Shell Programming and Scripting

script execute or no execute

o hola.. Tengo un script que se ejecuta bajo una tarea del CronJOb del unix, tengo la version 11 de unix, mi script tiene un ciclo que lee unos archivos .txt luego cada uno de esos archivos debe pasar por un procedimiento almacenado el cual lo tengo almacenado en mi base de datos oracle 10g,... (4 Replies)
Discussion started by: Kespinoza97
4 Replies
Login or Register to Ask a Question