I am relatively new to unix and linux bash scripting and have a few questions:
First here is my script:
for fileref in Ref/*.bed; do
for filename in Data/*.bed; do
bedops -e 1 $fileref $filename > "${fileref}${filename}.out"
done
done
I have want to perform the command bedops -e with the two files (which are gathered from looping through each directory) as input and have the output file be the concatenation of the two filenames (preferably without the .bed at the end). Is there a good way to do this?
You can use basename
to both drop the directory(*) and the extension:
for fileref in Ref/*.bed; do
for filename in Data/*.bed; do
bedops -e 1 $fileref $filename > "$(basename $fileref .bed)-$(basename $filename .bed).out"
done
done
(*) because for fileref in Ref/*
will iterate on Ref/File1
, Ref/File2
so keeping the directories your output file would look like `Ref/File1-Data/File2.out.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments