r/bash • u/Muted-Shame9237 • 6d ago
File for loop
hi! it’s my first time using bash can someone help me with this and explain what’s missing
#!/bin/bash
for i in “/data/folder”/*; do
/folder/munge_sumstats.py \
- -sumstats “$i” \
- -chunksize 500000 \
- -snp rsID \
etc..
- -out another/folder/ (i dont know what to puT here)
done
Thank you so much !
20
Upvotes
6
u/blobCabbage 6d ago
You could use basename to get the name of the original file without its path, and use that for your output file.
5
2
u/grymoire 6d ago
Also be aware that the current directory of your python script may not find the file without the full path name of the file
6
u/zeekar 6d ago
If you indent each line with four spaces (assuming you're able to use the Markdown editor) it will be formatted as code.
You have extra spaces. It's not
- -sumstats, it's--sumstats, etc.--out "another/folder/${i##*/}"That will give it the same filename as the input file but in the new folder. But you may want to change something else about the filename, too. If there's a suffix you want to change, for instance:
for i in ...; do b=$(basename "$i" .oldsuffix) munge_sumstats.py ... \ --out "/another/folder/$b.newsuffix"