I have a number of files with this pattern:file1_foo.extfile1_bar.extfile2_foo.extfile2_bar.extand so on.I need to pair them and put them in a file like thisfile1_foo.txt    file1_bar.txt(tab separated)What's the best course of action in this case?
Bash: pair up two series of files
bash;shell script;scripting
I assume you don't want to just assume both exist. This will only print the lines if they both exist.for file1 in *_foo.ext; do    file2=${file1%foo.ext}bar.ext    if [[ -e $file2 ]]; then        printf '%s\t%s\n' $file1 $file2    fidoneSample:$ tee {1,2,3}_foo.ext {1,3,4}_bar.ext </dev/null >/dev/null$ ./script1_foo.ext   1_bar.ext3_foo.ext   3_bar.ext