Re: bash: process substitution not working in script



On 4/29/2008 1:03 PM, lihao0129@xxxxxxxxx wrote:
I have a bash script which accept two input, one from a file, another
from the output of a shell pipeline. thought I can use process
substitution here, like:

awk -F'.' '
FNR == NR {
# do_sth();
next;
} {
# do_other_thing();
}
' file1.txt <( find -type f -exec file {}
+ | \
awk -F: '$2~/image/{split($1,b,"/");print
b[2]}' | \
sort -nk1 | uniq -
c' \
)

This works pretty well under command-line, but when I wrapped up
exactly the above lines into a shell script(since I need to test over
different directories), it did not work. the error shows:



./script.sh: line 30: syntax error near unexpected token `('
./script.sh: line 30: `' file1.txt <( find -type f -exec file {}
+ | \'

I checked the man page about the process substitution which mentioned
the named pipe. since I am not familiar with this part, could someone
help me with this problem? many thanks,


Since there's line-wrapping, etc. in your posting, it's hard to say what's
causing the problem, but in any case all you really need here is a pipeline:

find ... | awk ... | sort ... | uniq ... |
awk -F'.' '
FNR == NR {
# do_sth()
next
} {
# do_other_thing()
}
' file1.txt -

Note the "-" sign at the end to tell awk to read stdin after reading file1.txt.

Regards,

Ed.

.



Relevant Pages

  • Re: bash: process substitution not working in script
    ... from the output of a shell pipeline. ... substitution here, like: ... awk -F'.' ... FNR == NR { ...
    (comp.unix.shell)
  • Re: bash: process substitution not working in script
    ... from the output of a shell pipeline. ... FNR == NR { ... sort -nk1 | uniq - ... Note the "-" sign at the end to tell awk to read stdin after reading file1.txt. ...
    (comp.unix.shell)
  • Re: Sed1liners in Awk?
    ... where I could find the sed1liners done in awk. ... $ cat file1 ... File refs NR 1 FNR 1: ... a given search pattern is found). ...
    (comp.lang.awk)
  • Re: How-to use values from 2 input files
    ... FNR} ... That iwshy I would like to prefer awk. ... comment "because of the 'next' you are now in the second file; ... all lines in file2 or first row in file1 then first row in file2 then ...
    (comp.lang.awk)
  • Re: How to merge two files row by row?
    ... current input line and FNR is current input line in current file. ... What happens when the command is run? ... The next makes awk go and read next line so the second print ... block is never executed for file1. ...
    (comp.lang.awk)