Iterating over files and preforming operations on them

Connorr.0

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?

xenoid

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.

edited at
0

Comments

0 comments
Login to comment

Related

Iterating over glob patterns, not the files in them

Iterating over python files in a given directory and importing them?

Iterating over PE files

Iterating over folder to get csv files and merge them to separate sheets in excel

Iterating over a text files in a subdirectory

Iterating over files, splitting by pattern

Iterating over a list of strings for operations in Python

How to skip over a environment variable when iterating over them

FileNotFoundError in iterating over files under a directory

Iterating over files in Bash and obtaining the index and the counts

Iterating over .wav files in subdirectories of parent directory

Python iterating over excel files in a folder

Iterating over excel files in a directory: Openpyxl

Iterating over a directory of files using GNU Make

python iterating over files and appending to txt

What basic operations on a Map are permitted while iterating over it?

why is iterating over a Numpy array faster than direct operations

Multiple operations iterating over dataframe columns (apply function?)

rust reading lines amount file and iterating over them

Is it safe to delete an object property while iterating over them?

How to replace HashMap Values while iterating over them in Java

Can methods of objects be intercepted when iterating over them as part of a collection?

Iterating over records in one table and adding them to another with calculations

Can there be any problems deleting records when iterating over them in Tarantool?

Iterating over an array of objects and mapping them with custom key names in react

Modifying positional parameters while iterating over them in POSIX sh

loop over many files and plot them

Combine two json files and iterate over them

Calculating rate or percentage over certain amount of operations without storing them