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
CDPARANOIA(1)						      General Commands Manual						     CDPARANOIA(1)

NAME
cdparanoia 10.2 (Paranoia release III) - an audio CD reading utility which includes extra data verification features SYNOPSIS
cdparanoia [options] span [outfile] DESCRIPTION
cdparanoia retrieves audio tracks from CDDA capable CDROM drives. The data can be saved to a file or directed to standard output in WAV, AIFF, AIFF-C or raw format. Most ATAPI, SCSI and several proprietary CDROM drive makes are supported; cdparanoia can determine if the tar- get drive is CDDA capable. In addition to simple reading, cdparanoia adds extra-robust data verification, synchronization, error handling and scratch reconstruction capability. OPTIONS
-A --analyze-drive Run and log a complete analysis of drive caching, timing and reading behavior; verifies that cdparanoia is correctly modelling a sprcific drive's cache and read behavior. Implies -vQL. -v --verbose Be absurdly verbose about the autosensing and reading process. Good for setup and debugging. -q --quiet Do not print any progress or error information during the reading process. -e --stderr-progress Force output of progress information to stderr (for wrapper scripts). -l --log-summary [file] Save result summary to file, default filename cdparanoia.log. -L --log-debug [file] Save detailed device autosense and debugging output to a file, default filename cdparanoia.log. -V --version Print the program version and quit. -Q --query Perform CDROM drive autosense, query and print the CDROM table of contents, then quit. -s --search-for-drive Forces a complete search for a cdrom drive, even if the /dev/cdrom link exists. -h --help Print a brief synopsis of cdparanoia usage and options. -p --output-raw Output headerless data as raw 16 bit PCM data with interleaved samples in host byte order. To force little or big endian byte order, use -r or -R as described below. -r --output-raw-little-endian Output headerless data as raw 16 bit PCM data with interleaved samples in LSB first byte order. -R --output-raw-big-endian Output headerless data as raw 16 bit PCM data with interleaved samples in MSB first byte order. -w --output-wav Output data in Micro$oft RIFF WAV format (note that WAV data is always LSB first byte order). -f --output-aiff Output data in Apple AIFF format (note that AIFC data is always in MSB first byte order). -a --output-aifc Output data in uncompressed Apple AIFF-C format (note that AIFF-C data is always in MSB first byte order). -B --batch Cdda2wav-style batch output flag; cdparanoia will split the output into multiple files at track boundaries. Output file names are prepended with 'track#.' -c --force-cdrom-little-endian Some CDROM drives misreport their endianness (or do not report it at all); it's possible that cdparanoia will guess wrong. Use -c to force cdparanoia to treat the drive as a little endian device. -C --force-cdrom-big-endian As above but force cdparanoia to treat the drive as a big endian device. -n --force-default-sectors n Force the interface backend to do atomic reads of n sectors per read. This number can be misleading; the kernel will often split read requests into multiple atomic reads (the automated Paranoia code is aware of this) or allow reads only wihin a restricted size range. This option should generally not be used. -d --force-cdrom-device device Force the interface backend to read from device rather than the first readable CDROM drive it finds. This can be used to specify devices of any valid interface type (ATAPI, SCSI or proprietary). -k --force-cooked-device device This option forces use of the old 'cooked ioctl' kernel interface with the specified cdrom device. The cooked ioctl interface is obsolete in Linux 2.6 if it is present at all. -k cannot be used with -d or -g. -g --force-generic-device device This option forces use of the old 'generic scsi' (sg) kernel interface with the specified generic scsi device. -g cannot be used with -k. -g may be used with -d to explicitly set both the SCSI cdrom and generic (sg) devices seperately. This option is only use- ful on obsolete SCSI setups and when using the generic scsi (sg) driver. -S --force-read-speed number Use this option explicitly to set the read rate of the CD drive (where supported). This can reduce underruns on machines with slow disks, or which are low on memory. -t --toc-offset number Use this option to force the entire disc LBA addressing to shift by the given amount; the value is added to the beginning offsets in the TOC. This can be used to shift track boundaries for the whole disc manually on sector granularity. The next option does some- thing similar... -T --toc-bias Some drives (usually random Toshibas) report the actual track beginning offset values in the TOC, but then treat the beginning of track 1 index 1 as sector 0 for all read operations. This results in every track seeming to start too late (losing a bit of the beginning and catching a bit of the next track). -T accounts for this behavior. Note that this option will cause cdparanoia to attempt to read sectors before or past the known user data area of the disc, resulting in read errors at disc edges on most drives and possibly even hard lockups on some buggy hardware. -O --sample-offset number Use this option to force the entire disc to shift sample position output by the given amount; This can be used to shift track bound- aries for the whole disc manually on sample granularity. Note that this will cause cdparanoia to attempt to read partial sectors before or past the known user data area of the disc, probably causing read errors on most drives and possibly even hard lockups on some buggy hardware. -Z --disable-paranoia Disable all data verification and correction features. When using -Z, cdparanoia reads data exactly as would cdda2wav with an over- lap setting of zero. This option implies that -Y is active. -z --never-skip[=max_retries] Do not accept any skips; retry forever if needed. An optional maximum number of retries can be specified; for comparison, default without -z is currently 20. -Y --disable-extra-paranoia Disables intra-read data verification; only overlap checking at read boundaries is performed. It can wedge if errors occur in the attempted overlap area. Not recommended. -X --abort-on-skip If the read skips due to imperfect data, a scratch, whatever, abort reading this track. If output is to a file, delete the par- tially completed file. OUTPUT SMILIES
:-) Normal operation, low/no jitter :-| Normal operation, considerable jitter :-/ Read drift :-P Unreported loss of streaming in atomic read operation 8-| Finding read problems at same point during reread; hard to correct :-0 SCSI/ATAPI transport error :-( Scratch detected ;-( Gave up trying to perform a correction 8-X Aborted read due to known, uncorrectable error :^D Finished extracting PROGRESS BAR SYMBOLS
<space> No corrections needed - Jitter correction required + Unreported loss of streaming/other error in read ! Errors found after stage 1 correction; the drive is making the same error through multiple re-reads, and cdparanoia is having trou- ble detecting them. e SCSI/ATAPI transport error (corrected) V Uncorrected error/skip SPAN ARGUMENT
The span argument specifies which track, tracks or subsections of tracks to read. This argument is required. NOTE: Unless the span is a simple number, it's generally a good idea to quote the span argument to protect it from the shell. The span argument may be a simple track number or an offset/span specification. The syntax of an offset/span takes the rough form: 1[ww:xx:yy.zz]-2[aa:bb:cc.dd] Here, 1 and 2 are track numbers; the numbers in brackets provide a finer grained offset within a particular track. [aa:bb:cc.dd] is in hours/minutes/seconds/sectors format. Zero fields need not be specified: [::20], [:20], [20], [20.], etc, would be interpreted as twenty seconds, [10:] would be ten minutes, [.30] would be thirty sectors (75 sectors per second). When only a single offset is supplied, it is interpreted as a starting offset and ripping will continue to the end of the track. If a sin- gle offset is preceeded or followed by a hyphen, the implicit missing offset is taken to be the start or end of the disc, respectively. Thus: 1:[20.35] Specifies ripping from track 1, second 20, sector 35 to the end of track 1. 1:[20.35]- Specifies ripping from 1[20.35] to the end of the disc -2 Specifies ripping from the beginning of the disc up to (and including) track 2 -2:[30.35] Specifies ripping from the beginning of the disc up to 2:[30.35] 2-4 Specifies ripping from the beginning of track 2 to the end of track 4. Again, don't forget to protect square brackets and preceeding hyphens from the shell. EXAMPLES
A few examples, protected from the shell: Query only with exhaustive search for a drive and full reporting of autosense: cdparanoia -vsQ Extract an entire disc, putting each track in a seperate file: cdparanoia -B Extract from track 1, time 0:30.12 to 1:10.00: cdparanoia "1[:30.12]-1[1:10]" Extract from the beginning of the disc up to track 3: cdparanoia -- "-3" The "--" above is to distinguish "-3" from an option flag. OUTPUT
The output file argument is optional; if it is not specified, cdparanoia will output samples to one of cdda.wav, cdda.aifc, or cdda.raw depending on whether -w, -a, -r or -R is used (-w is the implicit default). The output file argument of - specifies standard output; all data formats may be piped. ACKNOWLEDGEMENTS
Cdparanoia sprang from and once drew heavily from the interface of Heiko Eissfeldt's (heiko@colossus.escape.de) 'cdda2wav' package. Cdpara- noia would not have happened without it. Joerg Schilling has also contributed SCSI expertise through his generic SCSI transport library. AUTHOR
Monty <monty@xiph.org> Cdparanoia's homepage may be found at: http://www.xiph.org/paranoia/ 11 Sep 2008 CDPARANOIA(1)
All times are GMT -4. The time now is 03:57 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy