shell - Read any .txt file in the folder through bash -
the idea want read .txt file in specific folder , something. tried code:
#!/bin/bash #read file line line while read line if [ $i -ne 0 ]; #do something... fi done < "*.txt" echo "finished!" i think got idea now. advice.
after doing stuff, want move file folder.
to avoid using cat unnecessarily, use for loop:
for file in *.txt while read line # whatever mv -i "$file" /some/other/place done < "$file" done this treats each file separately can perform actions on each 1 individually. if wanted move files same place, outside loop:
for file in *.txt while read line # whatever done < "$file" done mv -i *.txt /some/other/place as suggested in comments, have added -i switch mv, prompts before overwriting files. idea, when expanding * wildcard. if rather not prompted, instead use -n switch not overwrite files.
Comments
Post a Comment