LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-25-2021, 12:31 AM   #1
babag
Member
 
Registered: Aug 2003
Posts: 409

Rep: Reputation: 31
parsing output from sox to variables?


i have this line:
Code:
sox 27_TitleHere_Ch27.mp3 -n stats 2>&1 | sed -n 's#^Length s[^0-9]*\([0-9.]*\)$#\1#p'
which, in this case, returns this:
Code:
1008.327
how do i get that value into a variable? i'd like to be able to print something like:
Code:
echo duration : $variable
and have it print:
Code:
duration : 1008.327
thanks,
babag
 
Old 10-25-2021, 12:40 AM   #2
babag
Member
 
Registered: Aug 2003
Posts: 409

Original Poster
Rep: Reputation: 31
this seems to work:
Code:
test=$(sox 27_TitleHere_Ch27.mp3 -n stats 2>&1 | sed -n 's#^Length s[^0-9]*\([0-9.]*\)$#\1#p'); echo $test
thanks,
babag
 
Old 10-25-2021, 07:16 AM   #3
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,037

Rep: Reputation: Disabled
I'd just use soxi for this
Code:
var=$(soxi -D 27_TitleHere_Ch27.mp3)
 
Old 10-25-2021, 07:54 AM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 20,059

Rep: Reputation: 3671Reputation: 3671Reputation: 3671Reputation: 3671Reputation: 3671Reputation: 3671Reputation: 3671Reputation: 3671Reputation: 3671Reputation: 3671Reputation: 3671
Be worth rethinking your previous thread given this tool as well.
 
Old 10-26-2021, 05:11 PM   #5
babag
Member
 
Registered: Aug 2003
Posts: 409

Original Poster
Rep: Reputation: 31
thanks for the suggestions.

@shruggy, i actually had that soxi call in an earlier version of my script. i opted to keep things in sox, though, as i was parsing several other things from its 'stats' option that don't seem available in soxi and 'stats' does include the length info.

i definitely could rethink things in a number of ways but, for now, it seems to be working. i may post again if i get around to that rethinking.

thanks again,
babag
 
  


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
How to pipe or catch the output of SoX? General Linux - Software 2 09-27-2015 07:24 PM
[SOLVED] Can the sox command handle variables in shell scripts RedNeck-LQ Programming 7 09-12-2011 09:01 PM
[SOLVED] Parsing mountpoint from /etc/mtab (parsing "string") in C deadeyes Programming 3 09-06-2011 06:33 PM
sox package, Slackware 13.1, fails on sox 1.wav -e stat burbabro Slackware 1 05-04-2011 03:26 AM
how to stop parsing shell variables in bash script inside cat area? jackandking Linux - Newbie 2 03-10-2009 07:44 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:44 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
Open Source Consulting | Domain Registration