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

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -