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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Please help: Build a sed command and execute it in a script
# 8  
Old 07-18-2008
Quote:
cat test1.txt | $($sedcmd) > temp2.txt

where sedcmd = sed -n '/08465696_1215781522540/,/70225547_1215781581748/p'

I don't get an output in the temp2.txt. When I run the script in debug it states 'No such file or directory'
Firstly, you're not going to get any output in temp2.txt because you are passing "-n" which suppresses output.
Secondly, I'm still trying to figure out why you can't run a command when the command is stored inside a variable. sed seems to be executed, but it can't make sense of what I pass in. If I run sed from the command line with the same arguments, it works fine.

Last edited by cooldude; 07-18-2008 at 11:32 AM..
# 9  
Old 07-18-2008
Thats exactly what I get. When I run the command on the command line it works but not with the script. the /p at the end prints the range withinn. If you run the command it does produce an output.
# 10  
Old 07-18-2008
Not to hijack this topic, I've had problems like this before, except that I was passing variables to scripts, i.e.,
Code:
asdf="\( -name '*.hh' -o -name '*.cc' -o -name '*.c' \-o -name '*.h' \)"
find /usr $asdf

find, not the shell script, throws an error:
Code:
find: paths must precede expression

When I use the string and not the variable in the script, find works. I searched around, and I could not find an answer.
I've tried:
Code:
asdf="\( -name '*.hh' -o -name '*.cc' -o -name '*.c' \-o -name '*.h' \)"
or
asdf="\\( -name '*.hh' -o -name '*.cc' -o -name '*.c' \-o -name '*.h' \\)"
or
asdf="( -name '*.hh' -o -name '*.cc' -o -name '*.c' \-o -name '*.h' )"
or
asdf="( -name '*.hh' -o -name '*.cc' -o -name '*.c' \-o -name '*.h' )"
or
asdf="-name '*.hh' -o -name '*.cc' -o -name '*.c' \-o -name '*.h'"

Same results. I've been using python more recently.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Execute ssh command with additional terminal command to any remote user not working script

Hello i am having an issue with bash script and this is the code now=$(cat hosts1.txt | awk '{print $2;}') while read n ;do ssh root@$now 'useradd test1; echo -e "test1\ntest1" | passwd test1 && echo "test1 ALL=(ALL:ALL) ALL" >> /etc/sudoers' When i execute only part with cat, it... (8 Replies)
Discussion started by: tomislav91
8 Replies

2. 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

3. Shell Programming and Scripting

Build.xml invocation by Build Script

Hi I have a build.xml file and I can run it on Windows via cmd. Now I want to write a script to invoke the same. Is there a way to do this? (1 Reply)
Discussion started by: ankur328
1 Replies

4. Shell Programming and Scripting

Script runs but does not execute rm -rf command

Hi! First off I'm no bin/bash script writer! :( I can make heads and tales of it from the php experience I have and that's all. Now I managed to piece this script together to go look at directory and remove files that are +60 days. It's finding the files but its not removing them. I... (11 Replies)
Discussion started by: MrBiggz
11 Replies

5. Shell Programming and Scripting

When i am trying to execute export command within a shell script it is saying command not found.

I am running the export command within a view to use that value inside my build script. But while executing it it is saying "export command not found" My code is as follows: -------------------------- #!/bin/sh user="test" DIR="/bldtmp/"$user VIEW="test.view1" echo "TMPDIR before export... (4 Replies)
Discussion started by: dchoudhury
4 Replies

6. Shell Programming and Scripting

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: sed -i -e "s/^rm/\#rm/" -e "s/^tar/\#tar/" /path/to/file ... (3 Replies)
Discussion started by: DC Slick
3 Replies

7. Shell Programming and Scripting

exec a build command (adduser) in a script

Hi, With a awk script i create a "adduser line" $ cat /tmp/tmp.ldif | awk -f ldif2adduser.awk adduser --uid 1002 --gid 1000 --gecos "ROUSSIN Guy" --home /homeL/guy --shell /bin/bash --disabled-password guy If i cut and paste this line, all is fine. But in a shell script i get errors : ... (2 Replies)
Discussion started by: guyr
2 Replies

8. Shell Programming and Scripting

How to build a command in a script

Hi All I am trying to build a script that will take data from a tab separated file and use that to split up a quicktime file. So far the code is as follows #!/bin/sh #test parsing of data #fix excel file output returns cat $1 | tr "\r" "\n" > $1.fix printf "\n" >> $1.fix mv $1.fix $1 ... (3 Replies)
Discussion started by: babajuma
3 Replies

9. Shell Programming and Scripting

how to execute a sh command from a csh script

Hi everyone, I have a csh script that works fine but the output of an rsh command is different if I use boune shell instead cshell. Is there the possibility to execute only this command in bourne shell from a script declared cshell? Thanks Christian (2 Replies)
Discussion started by: bonovox
2 Replies

10. Shell Programming and Scripting

How to build a command into a string rather than execute the command

I'm trying to populate a command line into a variable. It appears to be executing, instead. Here's an example: mycmd='' if ...; then $mycmd='sudo ' fi $mycmd=$mycmd 'sed -i prev s/aaa/bbb/' $myfile res=`$mycmd` (I'm also not sure of the best way to execute the command from the... (1 Reply)
Discussion started by: littlejon
1 Replies
Login or Register to Ask a Question