Question

I have the following command to convert a raw file into float

x2x +sf < /raw-en/1.raw > /raw-f/1.f

I need to run it for all the files in the directory "raw-en"

Was it helpful?

Solution

That's a typical use-case for a for loop:

for file in /raw-en/*; do
    x2x +sf < $file > /raw-f/$(basename $file .raw).f
done

Edit: Fixed output directory as noted by @ederollora.

Edit[2]: You should consider using *.raw in the for-loop to suite your use-case (thanks again to @ederollora).

OTHER TIPS

You can loop over the files in the directory:

#!/bin/bash
for filename in /raw-en/*; do
    x2x +sf < "$filename" > /raw-f/"${filename%.*}.f"
done

This should fit your case.

PD: Extension change taken from: https://stackoverflow.com/a/4411117/2317111

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top