Want to parse output for variables in Bash


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Want to parse output for variables in Bash
# 8  
Old 05-03-2010
So far this is awesome! Going to have to run it against a few test MKV's to see that it's reliably getting that correct information - thank you so much!

Code:
# Adding a little routine to check the Pixel Width and Frames Per Second
MKVFPS=$( mkvinfo "$i" | awk -F "[ (]" '/Default duration:/ { print $(NF-5)}')
echo " *** Test MKV Information ***"
echo "MKVFPS: $MKVFPS"

MKVWIDTH=$( mkvinfo "$i" | awk -F "[ (]" '/Pixel width:/ {print $NF}')
echo "MKVWIDTH: $MKVFPS"

Outputs:
Code:
MKVFPS: 23.976
MKVWIDTH: 23.976

# 9  
Old 05-03-2010
Quote:
Originally Posted by randyharris
I tried that code exactly as shown above, and also as a 1 liner, but both times got this output:

Code:
awk: illegal primary in regular expression .*( at 
 source line number 2
 context is
	/ Default duration:/ >>>  {sub(".*\(","") <<<

Two solutions :
Code:
/ Default duration:/ {sub(".*\\(","");print $0 + 0}

Or
Code:
/ Default duration:/ {sub(/.*\(/,"");print $0 + 0}

Jean-Pierre.
# 10  
Old 05-03-2010
I was looking to leverage this to a very similar situation, in this other situation the pattern I am trying to match shows up in the information multiple times. Is there a way I can tell it to only return the 1st time after the pattern match and not continue to show the ones that show up afterwards.

e.g.:
width = 720
thisfield =
thatthat =
width = 853
thisotherfield =
thatotherfield =
width = 853

"width = " shows up multiple times, I would only like to see the value for the first, 720.

Last edited by randyharris; 05-03-2010 at 04:35 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing awk variables to bash variables

Trying to do so echo "111:222:333" |awk -F: '{system("export TESTO=" $2)}'But it doesn't work (2 Replies)
Discussion started by: urello
2 Replies

2. Shell Programming and Scripting

Parse variables from C++ to shell

Hi All, #include <iostream> int main() { std::int foo = 34; system("mkdir /home/linuxUser/fooDir"); system("vi fooFile") system("write foo in fooFile") foo = 43; foo = read foo from fooFile; std::cout << "foo = " << foo ; } result should be foo = 34 can... (3 Replies)
Discussion started by: linuxUser_
3 Replies

3. Linux

Parse ; deliminated variable to create variables

Hi there, would appreciate some help on this parsing problem if anybody can help im trying to parse a variable with the following output, each of the values im trying to parse are deliminated by a ; T192... (8 Replies)
Discussion started by: scottish_jason
8 Replies

4. Shell Programming and Scripting

parse output line using bash

hi, i have the followiing scenario where by i am parsing teh following output using cut -d like so #!/bin/bash output="ABCTable| ------------------| | ------------------| code | name | amount |" col1= $output | cut -d'|' -f5 col2= $output | cut -d'|'... (1 Reply)
Discussion started by: nano2
1 Replies

5. Shell Programming and Scripting

Need to parse lines in a file into two words and assign the values to two variables

For example, I have a file with below lines containing VOB tags and VOB paths. * /vobs/fts/FTSUSM20_VOB /ccvobsslx01/projects/vobs/eml/FTSUSM20_VOB * /vobs/fts/FTS20_VOB /ccvobsslx01/projects/vobs/eml/FTS20_VOB * /vobs/pmv/PMS_VOB /ccvobsslx01/projects/vobs/cpm/_/PMS_VOB *... (4 Replies)
Discussion started by: senthilkc
4 Replies

6. UNIX for Dummies Questions & Answers

Parse or cut concat variables to individual values

Hello I need to pass some environment parameters to a datastage job and am getting an error when trying to send the complete concatinated variable. I have decided to parse out just the values and send as parameters but am struggling to find the best way to do this (actually I am not very... (3 Replies)
Discussion started by: LynnC
3 Replies

7. Shell Programming and Scripting

Parse config file and store the values in variables

Hi, I have a config file that has blank, commented lines. I need to escape commented lines, blank lines, parse the remaining lines and store them in variables or array. the config file contains the following lines. # config file # Define Oracle User ORA_USER=abcde ORA_PASS=xyzabc... (8 Replies)
Discussion started by: Lakshmi Chowdam
8 Replies

8. Shell Programming and Scripting

How to parse a string into variables

I'm working in korn shell and have a variable which contains a string like: aa_yyyymmdd_bbb_ccc_ddd.abc. I want to treat the _ and . as delimiters and parse the string so I end up with 6 values in variables that I can manipulate. My original plan was to use var1=`echo $sting1 | cut -c1-c2` but... (9 Replies)
Discussion started by: aquimby
9 Replies

9. Shell Programming and Scripting

How to: Parse text string into variables using Korn shell

I am writing a script to keep check on free disk space, and I would like to find a way to parse $LINE (see code below) into a numeric value (for free disk space percentage) and a string value (for mount point). If possible, I would like to avoid sed or any additional use of awk since I am not very... (7 Replies)
Discussion started by: shew01
7 Replies

10. Shell Programming and Scripting

How can I parse a record found in /etc/passwd into variables?

I am working with the Oracle 10.2.0.3 job scheduler on Solaris 10, and unfortunately, the scheduler executes scripts in such a way that several default shell environment variables are not defined. For example, $HOME, $USER, and $LOGNAME are missing. How can I parse the appropriate record in... (7 Replies)
Discussion started by: shew01
7 Replies
Login or Register to Ask a Question