Sponsored Content
Top Forums Shell Programming and Scripting script to disc-at-once extract audio books with cdparanoia Post 302560082 by iconoclast hero on Wednesday 28th of September 2011 09:12:09 PM
Old 09-28-2011
Quote:
Originally Posted by agama
Using bash is perfectly acceptable. Kshell has a few features that make it more attractive to me, but that's a personal preference.

The 2>&1 causes output to stderr (file descriptor 2) to be written onto stdout (file descriptor 1) which is what the shell maps to the process on the other side of the pipe.

Some comments on the awk:
Code:
awk ' 
$1+0 > 0 {   # when the first field converted to a number is greater than 0
   n = $1+0; # save the first field as a number in variable n
   next;      # continue processing with next line of input (not required for this case, but good form)
} 

END {     # execute this code after the last line of input has been processed
   print n;  # print the value of n to standard output
}'

In short, awk reads the input file (or from the pipe a.k.a. stdin) and for each line of input executes the programme. In this case the programme is a very simple check to see if the first column (or field if you like that phrase) contains a digit, and if it does the code in curly braces is executed (saving that value in n).

It uses a bit of awk trickiness to do this. The field is added to 0 knowing that awk will convert any text string to 0 and for each record that does not start with a number (e.g. 1.) the result will be 0 + 0 and the condition will be false; the code will not be executed and n will not be changed.

Here's a link to a decent tutorial on awk -- worth the read as awk is one of the (IMHO) most useful tools available to a UNIX programmer.

You are only allowed to post URLs once you have at least 5 posts.

Hope this helps.
Ok, I think I understand what you're doing with awk, it is just so impenetrable at this point that it doesn't make much sense. I am best at learning by doing so an awk guide makes less sense to me than to tackle it via grep... That said, let me see if I understand your comment about awk, you said first column or field, but in reality, it is just the first character on the line that has to be a number, correct?

Also, I was able to get the right number, but I think your commented code has something wrong with it... I had to make the following modifications:

Code:
#END=$(cdparanoia -Q 2>&1| awk ' $1+0 > 0 { n=$1+0; next; } END { print n}' )

END=$(cdparanoia -Q 2>&1| awk ' $1+0 > 0 {              # when the first field converted to a number is greater than 0
   n = $1+0;                                            # save the first field as a number in variable n
   next;                                                # continue processing with next line of input (not required for this case, but good form)
     } 

END {                                                   # execute this code after the last line of input has been processed
   print n}')                                           # print the value of n to standard output


echo $END

 

9 More Discussions You Might Find Interesting

1. Solaris

Ultra 10 - Copying Files From Disc After Booting Up With Recovery Disc?

Hello, I'm still learning unix and I have what is probably a simple question but I can't seem to find the question to. I have an Ultra 10 Sparc Server running solaris 8 and the drive may have crashed (I hope not). Currently, it appears some files in the /etc folder are missing. I have a backup... (1 Reply)
Discussion started by: ideffects
1 Replies

2. Shell Programming and Scripting

Books for Shell Script and UNIX

Hi i am new to UNIX completely. i dont know any thing about UNIX. can some one please help me with some books on the unix archetecture and all the internal working of UNIX OS (i want to know every thing about unix from basics) and shell programming. can any one please if available provide... (1 Reply)
Discussion started by: amiman
1 Replies

3. Shell Programming and Scripting

Script to list files not present in audio.txt file

I am having following folder structure. /root/audios/pop /root/audios/jazz /root/audios/rock Inside those pop, jazz, rock folders there are following files, p1.ul, p2.ul, p3.ul, j1.ul, j2.ul, j3.ul, r1.ul, r2.ul, r3.ul And I have a file named as "audio.txt" in the path /root/audios,... (11 Replies)
Discussion started by: gopikrish81
11 Replies

4. Shell Programming and Scripting

Error with Audio Conversion Bash Script

Good evening, I'm currently working on a BASH script to convert audio between file formats and I've come across a snag. At the beginning of the script, I'm having the system check to see if any files with the .m4a extension exist in the directory, and if so, it runs the script. If there are no... (1 Reply)
Discussion started by: KBurkholder
1 Replies

5. Slackware

Problems with audio recording in Audacity 2.0.5. Slackware64 14.1; Intel HD Audio.

I'm trying to record audio using Audacity 2.0.5 installed from SlackBuilds. My system is 64-bit Slackware 14.1 and a sound card is Intel HD Audio. I didn't change my sound system to OSS. (Default sound system in Slackware 14.1 is ALSA, isn't it?) First, I set Internal Microphone slider in KMix... (2 Replies)
Discussion started by: qzxcvbnm
2 Replies

6. OS X (Apple)

Python script to do simple audio capture...

This site is the first to get this snippet. It will capture an audio recording of any time length within the limits of OSX's QuickTime Player's capablility... A shell script derivative of this will be used as a further capture for CygWin's AudioScope.sh. Thoroughly read ALL the comments in... (0 Replies)
Discussion started by: wisecracker
0 Replies

7. Shell Programming and Scripting

Need a script for automation the convert a lot number audio files to another format

I have a lot number audio files in the MP3 proprietary format, I want to convert them to 'opus' the free and higher quality format, with keep metadata also. My selection command-line programs are SoX (Sound eXchange) for convert MP3 files to 'AIFF' format in order to keep quality and metadata*... (1 Reply)
Discussion started by: temp-usr
1 Replies

8. Shell Programming and Scripting

The Start Of A Simple Audio Scope Shell Script...

This is a DEMO shell script to generate a simple graticule and plot inside it... Apologies for any typos... it is another building block along with my other two shell uploads recently to start a semi_serious project of an Terminal_AudioScope... The fist upload I posted recently was to show... (83 Replies)
Discussion started by: wisecracker
83 Replies

9. What is on Your Mind?

Neo's Recommended Audio Books

Just finished this Audible audio book. It's simply great. Highly recommended: This book was so well done that I did not want to miss a single word; so ended up listening to half of the book twice when I got distracted. This is a great audio book. ... (0 Replies)
Discussion started by: Neo
0 Replies
All times are GMT -4. The time now is 03:57 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy