Help on shell script (string operations)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help on shell script (string operations)
# 1  
Old 08-07-2010
Help on shell script (string operations)

Hey everyone. So the background of the problem is that the ps3 does not support the mkv container, but DOES support the avi one. Here is the script to convert one file with the name hardcoded in:


Code:
#!/bin/sh                                                                   
mencoder -oac mp3lame -lameopts cbr=128 -ovc xvid -xvidencopts bitrate=1200  VIDEO_NAME.mkv -o VIDEO_NAME.avi
rm subtitles.srt #Command creates a subtitles.srt file that I don't want

I would like to modify this script so that I can specify an input as a directory, and it will convert all mkv files to avi files with only the extensions changed (same file name).

I have limited experience in shell scripting, but I'd imagine I would have to do something like
Code:
for i in ls *.mkv

then do the original converting command with the string VIDEO_NAME.mkv and the modified string VIDEO_NAME.avi

Any help is greatly appreciated!

Last edited by Scott; 08-07-2010 at 02:25 PM.. Reason: Please use code tags
# 2  
Old 08-07-2010
Maybe this.
Code:
#!/bin/sh
cd "$1"  ||  { echo "Arg 1 must be a directory" 2>/dev/stderr; exit 1; }
OPTIONS="-oac mp3lame -lameopts cbr=128 -ovc xvid -xvidencopts bitrate=1200"
for f in *.mkv; do
    AVI="${f%.*}.avi"
    mencoder $OPTIONS "$f" -o $AVI
done

${f%.*} prints the contents of $f with everything stripped off from the last period to the end.
# 3  
Old 08-09-2010
Quote:
Originally Posted by KenJackson
Maybe this.
Code:
#!/bin/sh
cd "$1"  ||  { echo "Arg 1 must be a directory" 2>/dev/stderr; exit 1; }
OPTIONS="-oac mp3lame -lameopts cbr=128 -ovc xvid -xvidencopts bitrate=1200"
for f in *.mkv; do
    AVI="${f%.*}.avi"
    mencoder $OPTIONS "$f" -o $AVI
done

${f%.*} prints the contents of $f with everything stripped off from the last period to the end.
Thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell operations from C++

Hi everyone, I need little help in shell operations from C++ program. Here I furnish the details of problem: 1. Lets say my current working path is myWorkingPath. 2. In my working path I have list of name directories and each name directory has two more sub directories say A/B. (now path to... (5 Replies)
Discussion started by: linuxUser_
5 Replies

2. UNIX for Dummies Questions & Answers

Comparing a String variable with a string literal in a Debian shell script

Hi All, I am trying to to compare a string variable with a string literal inside a loop but keep getting the ./testifstructure.sh: line 6: #!/bin/sh BOOK_LIST="BOOK1 BOOK2" for BOOK in ${BOOK_LIST} do if then echo '1' else echo '2' fi done Please use next... (1 Reply)
Discussion started by: daveu7
1 Replies

3. Programming

shell cursor operations

Hi I need to save the actual cursor position into variable in my script. How can I do it ? thx for help. (1 Reply)
Discussion started by: presul
1 Replies

4. Shell Programming and Scripting

String operations

Can you give me some suggestions to split below string into three parts using shell scripts.. Script has to print all alphabets before the number, then number and then all alphabets after the number.. input: chris martin 200173 845747 mech engineer output: chris martin 200173 845747 mech... (6 Replies)
Discussion started by: nram_krishna@ya
6 Replies

5. Shell Programming and Scripting

String operations

Hi All, can you tell me how to drop all preceding zeros in a number. For example, if i have a numbers like 000876838347 and 0000007854762543..how to make them as 876838347 and 7854762543. (6 Replies)
Discussion started by: nram_krishna@ya
6 Replies

6. Shell Programming and Scripting

file operations in shell scripting

hi All, my query... 1.I Have to search for the files in the root directory. 2.i have to search for a pattern in all the files in the root directory and then replace them with a new pattern. 3.Rename the file Explanation: if ABC is the root folder and has 3 subfolders and there are 15... (9 Replies)
Discussion started by: adityamahi
9 Replies

7. Shell Programming and Scripting

Unix file operations(shell script)

Hi, I want to compare two files. Files will look like as follows: file1: ASDFGHJU|1234567890123456 QWERTYUI|3456789098900890 file2: ZXCVBVNM|0987654321234567 POLKIJUYH|1234789060985478 output file should be: ASDFGHJU|1234567890123456 QWERTYUI|3456789098900890 Thnaks in advance (6 Replies)
Discussion started by: nivas
6 Replies

8. UNIX for Dummies Questions & Answers

AlphaNumeric String Operations

Hi :) I am writing a ksh I have a string of general format A12B3456CD78 the string is of variable length the string always ends with numbers (here it is 78.. it can be any number of digits may be 789 or just 7) before these ending numbers are alphabets (here it is CD can even be... (3 Replies)
Discussion started by: lakshmikanth
3 Replies

9. Shell Programming and Scripting

String Operations

Hi All, Query 1 : I want to know how we can get a count of multipe occurrences of a particular expression in another string. For Eg. If my string is " 12" and i need to count the number of spaces preceeding 12 Query 2 : Also want to know how we can change the alignment of a... (9 Replies)
Discussion started by: Rohini Vijay
9 Replies
Login or Register to Ask a Question