bash - Read all files line by line in a directory and do a command on them -


i trying make script allow me read files in directory line line while doing command specific column of these files. files dealing .txt files have values separated commas. able execute code single file inputting text file script , outputting values not multiple files, goal. files read in order in in directory. here have far.

directory=$(/dos2unix/*.txt) file=$(*.txt") ifs="," "$file" in "$directory";     while read -ra line;                 if [ "${line[1]}" != "" ];                 echo -n "${line[*]}, hash value:"; echo "${line[1]}" | openssl dgst -sha1 | sed 's/^.* //'             else                 if [ "${line[1]}" == "" ];                     echo "${line[*]}, hash value:none";                 fi             fi     done done 

some of errors getting are:

$ ./orange2.sh /dos2unix/test1.txt: line 1: hello: command not found /dos2unix/test1.txt: line 2: goodbye: command not found /dos2unix/test1.txt: line 4: last: command not found ./orange2.sh: line 28: unexpected eof while looking matching `"' ./orange2.sh: line 33: syntax error: unexpected end of file 

any tips, suggestions, or examples?

thanks all

update

i looking copy of files contain command see in first if statement a.) keep files separate , b.) create copy contain updated value.

if want save file names in variable, use array=(a b c) syntax create array. there's no dollar sign. loop on array for item in "${array[@]}".

to read file while read loop, use while read; ...; done < "$file". it's odd-looking, file redirected loop whole.

files=(/dos2unix/*.txt)  file in "${files[@]}";     while ifs=',' read -ra line;         ...     done < "$file" done 

another way use cat concatenate files together, lets rid of outer for loop.

cat /dos2unix/*.txt | while ifs=',' read -ra line;     ... done 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -