matching if/else in bash script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting matching if/else in bash script
# 1  
Old 09-18-2012
matching if/else in bash script

I have a bash script that I want to certain actions if it finds a string in the filenames, and another action if it does not match the string in the filename. Both my individual 'for' statements work on their own, however when i put it all together it returns 'unexpected end of file error'. Can anyone tell me what I am doing wrong? Thanks so much.
Code:
#!/bin/bash
cd /Users/programmer/UPLOADS/s3-video
for f in $(find . -name "*4x3*" -type f -maxdepth 1);
do
/usr/local/ffmpeg -itsoffset -4 -i "$f" -vcodec mjpeg -vframes 1 -an -f rawvideo -s 404x300 "../s3-thumbnails/${f%.mp4}.1.jpg";
/usr/local/ffmpeg -itsoffset -8 -i "$f" -vcodec mjpeg -vframes 1 -an -f rawvideo -s 404x300 "../s3-thumbnails/${f%.mp4}.2.jpg";
/usr/local/ffmpeg -itsoffset -12 -i "$f" -vcodec mjpeg -vframes 1 -an -f rawvideo -s 404x300 "../s3-thumbnails/${f%.mp4}.3.jpg";
/usr/local/ffmpeg -itsoffset -16 -i "$f" -vcodec mjpeg -vframes 1 -an -f rawvideo -s 404x300 "../s3-thumbnails/${f%.mp4}.4.jpg";

for f in $(find . -not -name "*4x3*" -type f -maxdepth 1);
do
/usr/local/ffmpeg -itsoffset -4 -i "$f" -vcodec mjpeg -vframes 1 -an -f rawvideo -s 540x300 "../s3-thumbnails/${f%.mp4}.1.jpg";
/usr/local/ffmpeg -itsoffset -8 -i "$f" -vcodec mjpeg -vframes 1 -an -f rawvideo -s 540x300 "../s3-thumbnails/${f%.mp4}.2.jpg";
/usr/local/ffmpeg -itsoffset -12 -i "$f" -vcodec mjpeg -vframes 1 -an -f rawvideo -s 540x300 "../s3-thumbnails/${f%.mp4}.3.jpg";
/usr/local/ffmpeg -itsoffset -16 -i "$f" -vcodec mjpeg -vframes 1 -an -f rawvideo -s 540x300 "../s3-thumbnails/${f%.mp4}.4.jpg";
done

# 2  
Old 09-18-2012
Code:
#!/bin/bash
cd /Users/programmer/UPLOADS/s3-video
for f in $(find . -name "*4x3*" -type f -maxdepth 1);
do
/usr/local/ffmpeg -itsoffset -4 -i "$f" -vcodec mjpeg -vframes 1 -an -f rawvideo -s 404x300 "../s3-thumbnails/${f%.mp4}.1.jpg";
/usr/local/ffmpeg -itsoffset -8 -i "$f" -vcodec mjpeg -vframes 1 -an -f rawvideo -s 404x300 "../s3-thumbnails/${f%.mp4}.2.jpg";
/usr/local/ffmpeg -itsoffset -12 -i "$f" -vcodec mjpeg -vframes 1 -an -f rawvideo -s 404x300 "../s3-thumbnails/${f%.mp4}.3.jpg";
/usr/local/ffmpeg -itsoffset -16 -i "$f" -vcodec mjpeg -vframes 1 -an -f rawvideo -s 404x300 "../s3-thumbnails/${f%.mp4}.4.jpg";
done
for f in $(find . -not -name "*4x3*" -type f -maxdepth 1);
do
/usr/local/ffmpeg -itsoffset -4 -i "$f" -vcodec mjpeg -vframes 1 -an -f rawvideo -s 540x300 "../s3-thumbnails/${f%.mp4}.1.jpg";
/usr/local/ffmpeg -itsoffset -8 -i "$f" -vcodec mjpeg -vframes 1 -an -f rawvideo -s 540x300 "../s3-thumbnails/${f%.mp4}.2.jpg";
/usr/local/ffmpeg -itsoffset -12 -i "$f" -vcodec mjpeg -vframes 1 -an -f rawvideo -s 540x300 "../s3-thumbnails/${f%.mp4}.3.jpg";
/usr/local/ffmpeg -itsoffset -16 -i "$f" -vcodec mjpeg -vframes 1 -an -f rawvideo -s 540x300 "../s3-thumbnails/${f%.mp4}.4.jpg";
done

for starters try that.

I cannot see how this returns a "string" for you to process. Does each ffmpeg call display something useful?
# 3  
Old 09-18-2012
Also, the find might be returning files with quotes.

Change for lines to:

Code:
 
$(find . -name "*4x3*" -type f -maxdepth 1 | sed 's/"/\\"/g;  s/'\''/\\'\''/g');

Code:
$(find . -not -name "*4x3*" -type f -maxdepth 1 | sed 's/"/\\"/g;  s/'\''/\\'\''/g');

This will scape the quotes.
# 4  
Old 09-18-2012
Thanks a ton, rdrtx1...i am still an extreme newbie...needed the extra done statement. thanks also for the quote escaping, that is a good point, too Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies

2. Shell Programming and Scripting

Bash lookup matching digits for secong file

In the bash below the user selects the file to be used. The digits of each file are unique and used to automatically locate the next file to be used in the process. The problem I can not seem to fix is that the full path needs to be referenced in the second portion and it is not currently. Is... (7 Replies)
Discussion started by: cmccabe
7 Replies

3. Shell Programming and Scripting

Bash pattern matching question

I need to check the condition of a variable before the script continues and it needs to match a specific pattern such as EPS-03-0 or PDF-02-1. The first part is a 3 or 4 letter string followed by a hyphen, then a 01,02 or 03 followed by a hyphen then a 0 or a 1. I know I could check for every... (4 Replies)
Discussion started by: stormcel
4 Replies

4. Ubuntu

Bash to ash port, character-matching problem

I'm trying to convert this working bash script into an Ash script, read -p "Username:" _username if ! ]]; then echo "Valid" else echo "INVALID" fi However, Ash does not recognize the "=~" character. How can I do this? Also, is there a good reference guide, so I... (5 Replies)
Discussion started by: fzivkovi
5 Replies

5. Shell Programming and Scripting

Matching Numbers in Bash/AWK

Hi, I need to match up some numbers in one file to the closest numbers in other file and produce an output file. File one (f1.txt) is laid out like this PCode Lon Lat AB10 1AA 57.148235 -2.096648 BB2 3JD 53.728563 -2.47852 LU4 9ET... (4 Replies)
Discussion started by: ian_gooch
4 Replies

6. Shell Programming and Scripting

Regular expression matching in BASH (equivalent of =~ in Perl)

In Perl I can write a condition that evaluates a match expression like this: if ($foo =~ /^bar/) { do blah blah blah } How do I write this in shell? What I need to know is what operator do I use? The '=~' doesn't seem to fit. I've tried different operators, I browsed the man page for... (3 Replies)
Discussion started by: indiana_tas
3 Replies

7. Shell Programming and Scripting

making a list matching certain criteria in bash...

Hello everyone!I am trying to make a mail list(a simple .txt file)in which i put certain records that match specific criteria. Let's say that i have a(sorted by last column file)like this one: 0100567 Bla1 Lala1 100 1234567 Bla2 Lala2 80 8769029 Bla3 Lala3 70 1001007 ... (0 Replies)
Discussion started by: bashuser2
0 Replies

8. Shell Programming and Scripting

Matching in bash

I know how to do this in perl, but I want to do it in bash script. Hope some one could help me, many thanks! I have a file looks like this: AB_21423 ********* BC_123 ********* CD_343 ********* AB_289 ********* *************** *************** I... (5 Replies)
Discussion started by: zx1106
5 Replies

9. Shell Programming and Scripting

bash script, pattern matching + sum

Hi guys, i have been struggling to achieve the following and therefor looking for some help. I am trying to write something that will summerize the following output from my switches for daily totals. Basicly if $1 $2 $3 doesnt change, we can keep adding up $4. Probably would use a awk print end... (3 Replies)
Discussion started by: Wratholix
3 Replies

10. Shell Programming and Scripting

Pattern matching in BASH

i have 255 files in a directory named 000po.k thru 255po.k and I want to copy all files except 3: exclude 000po.k, 166po.k,168po.k I know the long way around it copying these files, but am looking for a shorter way of doing this: my old approach: # copy 001po.k thru 009po.k to target... (3 Replies)
Discussion started by: zoo591
3 Replies
Login or Register to Ask a Question