Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I want to run a command line tool that takes a file, manipulates it and exports a new file. I can use this command just fine for a single file, but would like to make it run through an entire folder of files of a specified extension. I'd like to name the newly created file based on the old file name, but change the first few letters of the file name to something I specify. Like this:

command newfile_same oldfile_same

Thanks for your help!

share|improve this question
1  
What command is it exactly? Perhaps it has already an option to do such batch operations? If I understood you correctly, the input and output names looks like *_same where "same" is literal? –  Lekensteyn Feb 21 '12 at 20:06
    
the command is: ogr2ogr -clipsrc clipping_polygon.shp output.shp input.shp . I'd like the output to use the input file name, but prefix it with whatever I decide (e.g. input is "file.shp" and the output becomes "prefix_file.shp" . Thank you. –  Paul Feb 22 '12 at 19:51

2 Answers 2

If you want to change all files in a directory, which have a special extension, you can use another for-Loop:

for FILE in *.extension; do
  command "newfile_$FILE" "$FILE";
done
share|improve this answer

You can use a for loop:

for FILE in "file1" "file 2" "another file"; do
  command "newfile_$FILE" "$FILE";
done
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.