Issue catching/reading 2 digits and 3 letter string between brackets


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Issue catching/reading 2 digits and 3 letter string between brackets
# 1  
Old 09-30-2014
Issue catching/reading 2 digits and 3 letter string between brackets

Hello

I'm writing a handler for ffmpeg, and having troubles to catch some exceptions that may occour with certain files.

In order to parse for video & subtitle maps, i've had to make the raw data easier to handle, until now this worked well, but basicly i've just been lucky...

The input data is looking like this (beeing in $TMP.info):
Code:
    Stream #0:0(eng): Video: h264 (High), yuv420p, 1920x1080, SAR 1:1 DAR 16:9, 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
    Stream #0:1(eng): Audio: truehd, 48000 Hz, 5.1(side), s32 (default)
    Stream #0:2(eng): Audio: ac3, 48000 Hz, stereo, fltp, 192 kb/s
    Stream #0:3(eng): Audio: ac3, 48000 Hz, stereo, fltp, 192 kb/s
    Stream #0:4(eng): Subtitle: hdmv_pgs_subtitle
    Stream #0:5(eng): Subtitle: hdmv_pgs_subtitle
    Stream #0:6(fre): Subtitle: hdmv_pgs_subtitle
    Stream #0:7(spa): Subtitle: hdmv_pgs_subtitle
    Stream #0:8(ger): Subtitle: hdmv_pgs_subtitle
    Stream #0:9(ara): Subtitle: hdmv_pgs_subtitle
    Stream #0:10(bul): Subtitle: hdmv_pgs_subtitle
    Stream #0:11(cze): Subtitle: hdmv_pgs_subtitle
    Stream #0:12(dan): Subtitle: hdmv_pgs_subtitle
    Stream #0:13(hrv): Subtitle: hdmv_pgs_subtitle
    Stream #0:14(fin): Subtitle: hdmv_pgs_subtitle
    Stream #0:15(gre): Subtitle: hdmv_pgs_subtitle
    Stream #0:16(heb): Subtitle: hdmv_pgs_subtitle
    Stream #0:17(hin): Subtitle: hdmv_pgs_subtitle
    Stream #0:18(hun): Subtitle: hdmv_pgs_subtitle
    Stream #0:19(ice): Subtitle: hdmv_pgs_subtitle
    Stream #0:20(nor): Subtitle: hdmv_pgs_subtitle
    Stream #0:21(pol): Subtitle: hdmv_pgs_subtitle
    Stream #0:22(rum): Subtitle: hdmv_pgs_subtitle
    Stream #0:23(srp): Subtitle: hdmv_pgs_subtitle
    Stream #0:24(slo): Subtitle: hdmv_pgs_subtitle
    Stream #0:25(slv): Subtitle: hdmv_pgs_subtitle
    Stream #0:26(swe): Subtitle: hdmv_pgs_subtitle
    Stream #0:27(tur): Subtitle: hdmv_pgs_subtitle
    Stream #0:28(rus): Subtitle: hdmv_pgs_subtitle

The mal-function parsing this input data:
Code:
	listIDs() { # [VIDEO]
	# Prints a basic table of stream ID CONTENT (and if found) LANG
	# If VIDEO is not passed, it is assumed that $TMP.info contains the current data
		[[ -z $1 ]] && \
			cmd="cat \"$TMP.info\"" || \
			cmd="StreamInfo \"$1\""
		eval $cmd |	while read strs maps kinds other;do
					kind="${kinds:0:-1}"
					lang="${maps:5:3}"
					id="${maps:3:1}"
					printf "$id \t $lang \t $kind\n"
				done
	}

Yes i am aware that strs and other are not used, but otherwise maps and kinds would contain to much data.
(for me to handle at least)

And then beeing processed by listIDs it looks like:
Code:
0 	 eng 	 Video
1 	 eng 	 Audio
2 	 eng 	 Audio
3 	 eng 	 Audio
4 	 eng 	 Subtitle
5 	 eng 	 Subtitle
6 	 fre 	 Subtitle
7 	 spa 	 Subtitle
8 	 ger 	 Subtitle
9 	 ara 	 Subtitle
1 	 (bu 	 Subtitle
1 	 (cz 	 Subtitle
1 	 (da 	 Subtitle
1 	 (hr 	 Subtitle
1 	 (fi 	 Subtitle
1 	 (gr 	 Subtitle
1 	 (he 	 Subtitle
1 	 (hi 	 Subtitle
1 	 (hu 	 Subtitle
1 	 (ic 	 Subtitle
2 	 (no 	 Subtitle
2 	 (po 	 Subtitle
2 	 (ru 	 Subtitle
2 	 (sr 	 Subtitle
2 	 (sl 	 Subtitle
2 	 (sl 	 Subtitle
2 	 (sw 	 Subtitle
2 	 (tu 	 Subtitle
2 	 (ru 	 Subtitle

So, i need help to:
1) get the 2 digits shown
2) where there should be 2 digits, print all 3 letters of the language, rather than a leading '('

Thank you in advance for any advice.

---------- Post updated at 23:07 ---------- Previous update was at 23:00 ----------

lol...
Right after posting, something i've just learned recently, came up in mind....

Code:
					lang="${maps/*\(/}"
					lang="${lang:0:-2}"
					id="${maps/\(*/}"
					id="${id:3}"

Did the trick.

Code:
0 	 eng 	 Video
1 	 eng 	 Audio
2 	 eng 	 Audio
3 	 eng 	 Audio
4 	 eng 	 Subtitle
5 	 eng 	 Subtitle
6 	 fre 	 Subtitle
7 	 spa 	 Subtitle
8 	 ger 	 Subtitle
9 	 ara 	 Subtitle
10 	 bul 	 Subtitle
11 	 cze 	 Subtitle
12 	 dan 	 Subtitle
13 	 hrv 	 Subtitle
14 	 fin 	 Subtitle
15 	 gre 	 Subtitle
16 	 heb 	 Subtitle
17 	 hin 	 Subtitle
18 	 hun 	 Subtitle
19 	 ice 	 Subtitle
20 	 nor 	 Subtitle
21 	 pol 	 Subtitle
22 	 rum 	 Subtitle
23 	 srp 	 Subtitle
24 	 slo 	 Subtitle
25 	 slv 	 Subtitle
26 	 swe 	 Subtitle
27 	 tur 	 Subtitle

# 2  
Old 09-30-2014
You could also use IFS to get read to parse the line:

Code:
IFS=' :()'
eval "$cmd"| while read strs map id lang ignore kind other
do
   printf "%s\t" "$id" "$lang" "$kind"
   printf "\n"
done
IFS=$OIFS

This User Gave Thanks to Chubler_XL For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

change each letter of a string

Is there a way to change each letter of a string to the next one in the alphabet, so that a becomes b and f becomes g, and digits become one unit bigger - 4 becomes 5 and 9 becomes 0. I want to change strings like ben123 to cfo234. (5 Replies)
Discussion started by: locoroco
5 Replies

2. UNIX for Advanced & Expert Users

grep string containing [] brackets

Hello, I am trying to grep string with square brackets. for example I want to grep the below string in log.txt file. This is a test thanks in advance. (2 Replies)
Discussion started by: sureshcisco
2 Replies

3. Shell Programming and Scripting

Perl | catching the letter 'Q' for exit.

Hi all, I made a simple script with a prompt menu in Perl. All working good, but I want to add an option while the program is running that on every time when the user press 'Q' the program will exit. I know I can use $SIG{'INT'} or any other %SIG option. This option is a unix signal which I... (3 Replies)
Discussion started by: RedGrinGo
3 Replies

4. Shell Programming and Scripting

First Letter in a String to be capitalized

Is there a way to cnvert first letter alone in a string to upper case. For eg: diamond should be converted to Diamond. Thanks in Advance, Kinny (6 Replies)
Discussion started by: kinny
6 Replies

5. Shell Programming and Scripting

Finding a letter in a string

How to check whether a particular string contains dot or not? Here I can not use grep as the string is not in a file. I will get this string from user input Thanks, (2 Replies)
Discussion started by: balamv
2 Replies

6. Shell Programming and Scripting

How to substitute brackets in the beginning of string in perl?

Hi, I have a string like this user can specify different query sets that is why "or" is mentioned: $string="]("; or $string="](("; or $string="]((("; or $string="]((((("; (1 Reply)
Discussion started by: vanitham
1 Replies

7. Shell Programming and Scripting

Deleting part of a string enclosed in brackets

I use otool on OS X to figure out the shared libraries that a binary uses. I run this command: otool -L /Applications/Vidnik\ 0.13.0/Vidnik.app/Contents/MacOS/Vidnik And it returns an output similar to this: /Applications/Vidnik 0.13.0/Vidnik.app/Contents/MacOS/Vidnik:... (10 Replies)
Discussion started by: pcwiz
10 Replies

8. Shell Programming and Scripting

dead.letter issue

Hi, I have created a script that has some sql queries in it. It seem to work fine and e-mails me the output file but when i use this command 'col email format a20' it creates a dead.letter file and i never get the e-mail I am using mailx -s command to send out the e-mail. Any help would... (0 Replies)
Discussion started by: shawnk
0 Replies

9. Shell Programming and Scripting

substitution of string in brackets

Hi friends! I have a tab delimited file with two columns : GB_45_DRB SP:0139466(mrmi sisignm)|SP:3674(fllflg_itoioh)|SP:68954779(RMTKLGF to emmdm-roomto) GB_45_DRD SP:475928(mgmdksi rikgkg)|SP:587959(roykgl tiic-tm)|SP:0139466(mrmi sisignm)|SP:3674(fllflg_itoioh)|SP:68954779(RMTKLGF to... (4 Replies)
Discussion started by: jacks
4 Replies

10. Shell Programming and Scripting

get only two letter from any string

I want get middle two latter of any string. Input: var="070108" output: var1="01" please help. (2 Replies)
Discussion started by: rinku
2 Replies
Login or Register to Ask a Question