Use Xargs to wait for enter key

569 views Asked by At

So, I have a list of files that I want to use to generate a new set of groups of files. I want to open up these groups (multiple files) together at once. Edit them. Then go back to the terminal, hit enter, and open up the next group of files.

I've got it working, but I'm using a temporary file to do it like so

cat failingAll | awk '{print $2}' | xargs -I {} -L 1 sh -c "find {} | grep xml | xargs echo;" | perl -pe "s/^(.*)$/open \1;read;/g" > command.sh ; sh command.sh

Is this possible to do with just the xargs? Really, I mean without a temporary file. I tried this

cat failingAll | awk '{print $2}' | xargs -I {} -L 1 sh -c "find {} | grep xml | xargs open ; read;"

but it does not pause in between the groups, it just opens them all at once (and crashes my xml editor.)

2

There are 2 answers

7
Etan Reisner On BEST ANSWER

Try something like this and just quit the editor when you finish editing each group of files?

while IFS= read -r dir; do
    files=()
    while IFS= read -r -d '' xmlfile; do
        files+=("$xmlfile")
    done < <(find "$dir" -name "*.xml" -type f -print0)
    open -W "${files[@]}"
done < <(awk '{print $2}' failingAll)

Assuming you don't want to have to quit the editor and assuming it can take a new set of files via a subsequent call to open then the following might also work:

while IFS= read -u 3 -r dir; do
    files=()
    while IFS= read -r -d '' xmlfile; do
        files+=("$xmlfile")
    done < <(find "$dir" -name "*.xml" -type f -print0)
    open "${files[@]}"
    read
done 3< <(awk '{print $2}' failingAll)
0
Carlos Bribiescas On

In light of Etan Reisner's answer, I found this also works

cat failingAll | awk '{print $2}' | xargs -I {} -L 1 sh -c "find {} | grep xml | xargs open -W"

But it doesn't quite do what I wanted either which is wait for an enter. I believe its because xargs keeps feeding it the next line which breaks the read command.