LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-31-2009, 07:23 PM   #1
erickFis
Member
 
Registered: Jun 2003
Location: Brasil
Distribution: Slackware 13.1_64 Gold Edition
Posts: 209

Rep: Reputation: 32
Using sed to prepare my input file


Hello!

I have this file:

Code:
[tcscan] audio frames=685.42, estimated clip length=27.42 seconds
[tcscan] (min/max) amplitude=(-0.404/0.398), suggested volume rescale=2.473
[tcscan] V: 685 frames, 27 sec @ 25.000 fps
[tcscan] A: 0.41 MB @ 128 kbps
USER CDSIZE:  650 MB | V:  649.6 MB @ 197089.8 kbps
USER CDSIZE:  700 MB | V:  699.6 MB @ 212260.2 kbps
USER CDSIZE: 1300 MB | V: 1299.6 MB @ 394304.6 kbps
USER CDSIZE: 1400 MB | V: 1399.6 MB @ 424645.4 kbps
and I want to use sed or alike to extract this little piece of info:


Code:
[tcscan] (min/max) amplitude=(-0.404/0.398), suggested volume rescale=2.473
That is, I need only the 2.473 part.

How can I extract it?
 
Old 10-31-2009, 07:48 PM   #2
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233
You could use awk to do it:
Quote:
awk -F= '/rescale/ { print $3 }' file
 
Old 10-31-2009, 07:49 PM   #3
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
try produce your code next time.
Code:
$ awk -F"=" '/tcscan.*volume.*rescale/{print $NF}' file
2.473
 
Old 10-31-2009, 08:16 PM   #4
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233
In Sed, the following should work fine:

Code:
sed -n '/rescale/s/\(.*=\)\(.*\)/\2/p' file
 
Old 11-04-2009, 05:33 AM   #5
erickFis
Member
 
Registered: Jun 2003
Location: Brasil
Distribution: Slackware 13.1_64 Gold Edition
Posts: 209

Original Poster
Rep: Reputation: 32
Quote:
Originally Posted by ghostdog74 View Post
try produce your code next time.
Code:
$ awk -F"=" '/tcscan.*volume.*rescale/{print $NF}' file
2.473
Thank you all!
It works!

I really enjoy writing my own code,
but sometimes I get stuck......

Just to add a little more info to this thread:

awk -F= '/rescale/ { print $3 }' lista

prints me the result I want,

and

num=`awk -F= '/rescale/ { print $3 }' lista`

adds the result to the $num variable,
therefore I can use it later in the script.

Thanks again!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] awk or sed to use CSV as input and XML as template and output to a single file bridrod Linux - Newbie 6 03-13-2012 08:00 PM
sed delete lines from file one if regexp are listed in file two fucinheira Programming 6 09-17-2009 09:28 AM
using sed to insert line into file and overwrite the current file jadeddog Programming 3 06-11-2009 08:14 PM
sed: print section of file from string to end of file samyboy Linux - Newbie 4 02-26-2008 08:23 AM
sed input from `ls` rashy49 Programming 4 03-06-2005 03:31 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:43 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration