How to build a command in a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to build a command in a script
# 1  
Old 11-04-2008
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


FILE=$1

coffee_out=""
coffee_fill="‑splitAt"
coffee_end="‑self‑contained ‑o output.mov $2"
textArray[0]="" # hold text
c=0 # counter
# read whole file in loop

while read c_out line
do
if test $c_out #check there is a value especial for /n for the fix from excel
then
textArray[$c]="$c_out $line" # store line
c=$(expr $c + 1) # increase counter by 1
coffee_out="$coffee_out $coffee_fill $c_out"
fi
done < $FILE


coffee_out="$coffee_out $coffee_end"

echo $coffee_out
splitmovie "$coffee_out"
#The final output should look something like
#splitmovie -splitAt 2 -splitAt 3 -self-contained -o output.mov recode.mov
exit 0

I call the script with two arguments the text file and the quicktime

./split.sh testdata.txt recode.mov

I am a newbie at writing scripts so it could be something really dumb.

I think it is most likely to be me using the wrong way to set the input for splitmovie.

Thanks for your help

Michael
# 2  
Old 11-04-2008
How to handle the - in building a command in the sh script

Ok

i think i am hopefully focusing in on where the problem is.

when i print out $coffee_out at the end and look at it in a hex editor
the line looks like
splitmovie ...splitAt 3 ...self...contained ...o sdfsf.mov recode.mov.

Yet if i write it out by hand i get

splitmovie -splitAt 3 -self-contained -o sdfsf.mov recode.mov

It looks like i am not handling the - properly in the script

Any pointer would be gratefully appreciated

many thanks

michael
# 3  
Old 11-04-2008
Quote:
Originally Posted by babajuma
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

There's no need for cat:

Code:
tr "\r" "\n" < "$1" > "$1.fix"

Quote:
printf "\n" >> $1.fix
mv $1.fix $1

Quote your variables, or the script will fail if any filenames contain spaces.

Code:
printf "\n" >> "$1.fix"
mv "$1.fix" "$1"

Quote:


FILE=$1

coffee_out=""
coffee_fill="‑splitAt"
coffee_end="‑self‑contained ‑o output.mov $2"
textArray[0]="" # hold text
c=0 # counter
# read whole file in loop

while read c_out line
do
if test $c_out #check there is a value especial for /n for the fix from excel

Code:
if test -n "$c_out"

Quote:
then
textArray[$c]="$c_out $line" # store line
c=$(expr $c + 1) # increase counter by 1

There's no need for expr in the standard UNIX shell:
Code:
c=$(( $c + 1 ))

# 4  
Old 11-05-2008
- and -

Apparently there are two different types of -

And the ones i where using where the wrong ones.

I am not sure how i got the wrong ones into my script but a few copy and pastes and now it is working.

Thank you for your help on how to improve my script so far.

many thanks

michael
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

2. UNIX for Dummies Questions & Answers

Adding SDK Build on Kernel Source Build

Hi, So I downloaded this kernel source and was able to build it successfully. But I want to add this SDK source code inside, can anyone help me how to do this? Note that the SDK source can be built by itself. I added the SDK in the main Makefile: init-y := init/ #added SDK... (0 Replies)
Discussion started by: h0ujun
0 Replies

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

4. Shell Programming and Scripting

Select command to build menu

Hello everyone. I am using the select command to build a menu, here is my question: Is it possible to generate a menu which contains several sections and have a separator between the sections without having a selection number generated in front of the separator? This is a sample of what I would... (1 Reply)
Discussion started by: gio001
1 Replies

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

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

7. Shell Programming and Scripting

Build script for all shells

Hi, I made a build script for the product I am working on. The script was made in the /bin/sh shell. My first line in the script (after the #! /bin/sh and following # lines ) were, if ; then /bin/sh fi; It works well with my sh shell. I run the script as sh build.sh Now I... (9 Replies)
Discussion started by: vino
9 Replies

8. Shell Programming and Scripting

I want to build a script

I have this script sed -e '$q' -e 's/I/D/g' <inputfile> outfile which replaces I by D... I have to run this script in 90 files which their filename starts with CD*. I want to call all these files and execute this command once. Or schedule it to be executed at 1600hrs every day. I want... (7 Replies)
Discussion started by: mewalter
7 Replies

9. Shell Programming and Scripting

Script Build

I have a 3 status option 1 , 4 , 6 1 - Active 4 - Temp.. 6 - Deactive I want to build a script which when it finds either of the status options (1,4,6), then returns the relevant string. txs :confused: (3 Replies)
Discussion started by: mewalter
3 Replies

10. Shell Programming and Scripting

I want to build a script

I have file which has "A" character in more than 1000 lines and I want replace this "A" with "f". There is also "A" which I don't want to replace at the last line. Currently, I use this script to replace them one by one :g/A/s//f/g Regards (2 Replies)
Discussion started by: mewalter
2 Replies
Login or Register to Ask a Question