How to skip if file not found in bash?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to skip if file not found in bash?
# 8  
Old 09-21-2018
Why shouldn't you be able to "grab the "language" field"?
# 9  
Old 09-21-2018
As per your question, I have to edit the script as follows, that was my fault.
I should have mentioned that language field has relation with srt field.

Code:
for file in *.mp4
do
/root/bin/ffmpeg -i $file \
-i $(basename "${file/.mp4}").bos.srt \
-i $(basename "${file/.mp4}").dan.srt \
-i $(basename "${file/.mp4}").slo.srt \
-i $(basename "${file/.mp4}").swe.srt \
-map 0:v -map 0:a \
-map 1 -map 2 -map 3 -map 4 \
-c:v copy -c:a copy -c:s copy  -metadata:s:s:0 \
language=bos -metadata:s:s:i language=dan -metadata:s:s:(i+) 
language=slo -metadata:s:s:(i++) language=swe "${file/.mp4}")_output.mp4
done

tag of srt extension refers to language. If it finds *.bos.srt, it will put language=bos , bosnian language etc.
if it finds slo.srt, language should be language=slo etc.. Metadata nr increases as more srt file is found as it goes.

I am sorry again
# 10  
Old 09-21-2018
So it is different from what you posted first?

Last edited by RudiC; 09-21-2018 at 05:33 PM..
# 11  
Old 09-21-2018
No, not much... Language names are variable and connected to found srt files but not a big problem Rudic. Thank you so much for your support. I will find a way to sort the last part.


Kind regards
Boris
# 12  
Old 09-21-2018
Given the language code is the same in filenames and the metadata specification, try

Code:
for file in *.mp4
  do    printf -vINCLUDE -- "-i %s "  ${file/.mp4}*.srt
        T1=( ${INCLUDE//-i} )
        T2=( ${T1[@]%.*} )
        for (( i=0; i<${#T2[@]};i++)) do        ML=$ML" -metadata:s:s:$i language=${T2[i]#*.}"
                                                MP=$MP" -map $((i+1))"
                                       done
        echo /root/bin/ffmpeg -i $file "$INCLUDE" "$MP" "$ML"
        unset ML MP INCLUDE T1 T2
  done
/root/bin/ffmpeg -i FILE1.mp4 -i FILE1.dan.srt -i FILE1.slo.srt  -map 1  -map 2   -metadata:s:s:0 language=dan -metadata:s:s:1 language=slo
/root/bin/ffmpeg -i FILE2.mp4 -i FILE2.bos.srt -i FILE2.dan.srt -i  FILE2.slo.srt -i FILE2.swe.srt  -map 1 -map 2 -map 3 -map 4    -metadata:s:s:0 language=bos -metadata:s:s:1 language=dan  -metadata:s:s:2 language=slo -metadata:s:s:3 language=swe
/root/bin/ffmpeg -i FILE3.mp4 -i FILE3.bos.srt -i FILE3.dan.srt -i  FILE3.swe.srt  -map 1 -map 2 -map 3   -metadata:s:s:0 language=bos  -metadata:s:s:1 language=dan -metadata:s:s:2 language=swe


Last edited by RudiC; 09-21-2018 at 06:06 PM..
This User Gave Thanks to RudiC For This Post:
# 13  
Old 09-21-2018
Dear Rudic,
All ok now. I put space between map and $ sign in here, (as you did also) :
Code:
MP=$MP" -map $((i+1))"

Then, I had to change below part as language info was not giving the same result with yours:
Code:
language=${T2[i]#*.}"

to:
Code:
language=${T2[i]#.}"

Thank you so much again.

Kind regards
Boris
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash to search file for string and lauch function if found

In the bash below I am searching the filevirus-scan.log for the Infected files: 0 line (in bold) and each line for OK. If both of these are true then the function execute is automatically called and processing starts. If both these conditions are not meet then the line in the file is sent to the... (2 Replies)
Discussion started by: cmccabe
2 Replies

2. Shell Programming and Scripting

Bash - trap error file not found

Hello. In bash, is there a way to trap error "file not found" when a script call another script which is not found; then abort. Example ( part of script running with -x option set) : + return 0 + RETURN_CODE=0 + ] + /root/bin/200_yast_install/00_reset_yast_install bash:... (5 Replies)
Discussion started by: jcdole
5 Replies

3. Shell Programming and Scripting

Special case to skip function in bash menu

In the bash menu below if the variant that is inputted is in the format NM_004004.3:c.274G>T the below works perfectly. My question is if the variant inputted isNM_004004.3:-c.274G>T or NM_004004.3:+c.274G>T then the code as is will throw an error due to a biological issue. Is it possible to to... (1 Reply)
Discussion started by: cmccabe
1 Replies

4. UNIX for Dummies Questions & Answers

Using awk to skip record in file

I need to amend the code blow such that it reads a "black list" before the "print" statement; if "substr($1,1,6)" is found in the "blacklist" it will ignore that record and continue. the code is from an awk script that is being called from shell script which passes the input values. BEGIN { "date... (5 Replies)
Discussion started by: bazel
5 Replies

5. Shell Programming and Scripting

-bash-3.2$: not found

I am wondering if someone can help me out. I am new to oracle and given a task to install Oracle 11g on Solaris. I am running into some major problems since last week since I can't seem to get it to work. I can't start GUI, tried different blogs but no luck. Then, I decided to install it in a... (4 Replies)
Discussion started by: newborndba
4 Replies

6. UNIX for Dummies Questions & Answers

File Not found - Bash script

I'm facing issues in executing the bash script of mine. This script will pick the latest file received and connects SFTP server and files is placed on this remote server. Error message Enter password: "File movement" sftp> cd Test sftp> put Test_File_201309.txt File "Test_File_201309.txt"... (6 Replies)
Discussion started by: parpaa
6 Replies

7. UNIX for Dummies Questions & Answers

Im new to bash scriping and i found this expression on a bash script what does this mean.

# check host value regex='^(||1|2|25)(\.(||1|2|25)){3}$' if ')" != "" ]; then if ]; then echo host $host not found exit 4 fi elif ]; then echo $host is an invalid host address exit 5 fi espeacailly the top regex part? ---------- Post updated at 06:58 PM ---------- Previous update was... (1 Reply)
Discussion started by: kevin298
1 Replies

8. Shell Programming and Scripting

bash script search file and insert character when match found

Hi I need a bash script that can search through a text file and when it finds 'FSS1206' I need to put a Letter F 100 spaces after the second instance of FSS1206 The format is the same throughout the file I need to repeat this on every time it finds the second 'FSS1206' in the file I have... (0 Replies)
Discussion started by: firefox2k2
0 Replies

9. HP-UX

bash...Not found through where(compiling source file)

Hi i have compiled and installed bash 3.2 on my hp-ux parisc its in path /usr/local/pkg/bash/bin/bash .....When im search for this bash (through whereis bash) im not findind but other which i hve done in same procedure( gettext,m4) ..Im able to find through whereis search option can any1... (3 Replies)
Discussion started by: vasanthan
3 Replies

10. UNIX for Dummies Questions & Answers

skip reading certain lines in a file

How can I exclude reading lines in a file that contains the following: filesystem:/home/pach/liv_patches 128005120 88456640 37270758 71% /home/patches That is, all lines that contain and begins with filesystem: should not be processed/read from a file (5 Replies)
Discussion started by: paulsew
5 Replies
Login or Register to Ask a Question