Piping a file list for another shell command

Yen-Chung Chen
Dec 15, 2018 · 2 min read
Photo by Kyle Glenn on Unsplash
# There are 6 files in my example directory
> ls
1.txt 2.txt 3.txt a.txt b.txt c.txt
# Let's say we are looking for only those with lower case alphabetical names
> find . -regex "./[a-z].txt"
./c.txt
./b.txt
./a.txt
find . -regex “./[a-z].txt" | cat > "merged.txt"
# Awk will pass each file name to the system call (cat $0)
# and *append* it to a file because now the results are processed separately and will overwrite each other if we use > instead of >>
find . -regex “./[a-z].txt" | awk '{system("cat " $0 " >> 'merged.txt'")}'
  • If you are unsure what xargs is going to do, -p turns it interactive, and it prints the command that is elicited by xargs and asks whether you want to run it.
  • If you just want to know what command xargs elicits, -t prints the command (to stderr) before it is actually running without asking.

biosyntax

Notes, thoughts, and random experiments in life science.

Yen-Chung Chen

Written by

A learning developmental biologist

biosyntax

biosyntax

Notes, thoughts, and random experiments in life science.