Re: loop through records
awk may be a help here. Using it, you can refer to fields, like so: $ cat f1 187431346 0323 mirrored 11866 187431346 0324 mirrored 11866 187431346 0325 mirrored 11866 187431346 0326 mirrored 11866 $ awk '{print $1;print$2}' f1 187431346 0323 187431346 0324 187431346 0325 187431346 0326 On Wed, Mar 11, 2009 at 4:11 PM, OnTheEdge duaneschweit...@gmail.com wrote: All, I'm trying to figure out how to loop through an array of records (if possible) and reference fields in that record, but I've only been able to reference the entire array (array[0]) or when assigned with parens, there is no concept of a row... #!/bin/bash array1=187431346 0323 mirrored 11866 187431346 0324 mirrored 11866 187431346 0325 mirrored 11866 187431346 0326 mirrored 11866 element_count1=${#array1[*]} echo $element_count1 number_of_elements=${#arra...@]} echo '- ARRAY-1' for REC in ${array1[*]} do echo Field 1: ${REC[0]} Field 2: ${REC[1]} done I would like to see something like this: Field 1: 187431346 Field 2: 0323 Field 1: 187431346 Field 2: 0324 Field 1: 187431346 Field 2: 0325 Field 1: 187431346 Field 2: 0326 Thanks -- View this message in context: http://www.nabble.com/loop-through-records-tp22463462p22463462.html Sent from the Gnu - Bash mailing list archive at Nabble.com.
Re: implementing flow control in bash
Works perfectly, thanks! I'll study up on the syntax... Tony On Tue, Oct 21, 2008 at 5:30 PM, Bernd Eggink [EMAIL PROTECTED] wrote: Tony Zanella schrieb: Hello all, I'm sure this isn't a bug, but just my inability to wrap my head around enough of bash flow control: I wrote the following shell script to find all gifs in a directory. Then use identify from imagemagick to grab the gif width. Then, print the image name and width to a file. for i in `find . -name \*gif`; do identify -format $i %w $i; done results.txt Then, I used a ruby script to cull only those images with a width over 570 pixels. So, problem solved, but I wanted to see if I could do it all in bash. More specifically, (if this makes sense) I want to do identify -format $i %w $i only for those $i %w where %w is 570. The above script will give me output like: image1.gif 360 image2.gif 780 But I want it to give me: image1.gif 360 In pseudo-code, I want something like: for i in `find . -name \*gif`; do identify -format $i %w $i if [%w 570]; done results.txt for i in $(find -name '*.gif') do w=$(identify -format %w $i) (( w 570 )) echo $i $w done Hope that helps, Bernd -- Bernd Eggink http://sudrala.de
implementing flow control in bash
Hello all, I'm sure this isn't a bug, but just my inability to wrap my head around enough of bash flow control: I wrote the following shell script to find all gifs in a directory. Then use identify from imagemagick to grab the gif width. Then, print the image name and width to a file. for i in `find . -name \*gif`; do identify -format $i %w $i; done results.txt Then, I used a ruby script to cull only those images with a width over 570 pixels. So, problem solved, but I wanted to see if I could do it all in bash. More specifically, (if this makes sense) I want to do identify -format $i %w $i only for those $i %w where %w is 570. The above script will give me output like: image1.gif 360 image2.gif 780 But I want it to give me: image1.gif 360 In pseudo-code, I want something like: for i in `find . -name \*gif`; do identify -format $i %w $i if [%w 570]; done results.txt Any suggestions? Tony
how do I write a shell script to batch rename files in a directory?
Hello all, I have a directory listing of files like: img.bc03.547.1.gif? I need to trim the last character off for each file in the dir. I know I can use: mv img.bc03.547.1.gif? img.bc03.547.1.gif to rename each by hand, but I want to do this as a batch. I know it would start with: for files in *; do; after that, I'm stuck! Any suggestions?