bash read file
Sample of while loop to process input
Another way to read a file via cat and a pipe.
You can use a semicolon to combine commands on one line.
Code:
#!/bin/sh ################################## # Purpose: Cleanup any confirmation reports (*.pdf) older than xx days # Called By: batch daily cleanup process, /Applications/xyz/distributor.sh # Author: jeb # Date: 4/20/07 # Comments: The while loop is preferred over the find -exec rm {} syntax because it # does not spawn a process for each file to be deleted. # The script expects (*.pdf) instead of (*.PDF) but the script would work # in case of (*.PDF) as the testing showed shell to be case insensitive. # -mtime +30 yields files modified more than 30 days ago # -mtime -10 would yield files modified less than 10 days ago ################################## find /abc/xyz/reports/confirmations -type f -name "*.pdf" -mtime +30 > cleanuplist while read -r filename do print "deleting " $filename rm $filename done < cleanuplist
You can use a semicolon to combine commands on one line.
Code:
while read line; do echo $line; done
Code:
cat thefile | while read firstWord secondWord restOfLine do echo $firstWord echo $secondWord echo $restOfLine # do other stuff like ls -l "$firstWord" done
Total Comments 0