Reputation: 53
I have a txt file which contain a big list of files. Each filename is 1 row in the list.
I was able to read it like this :
#!/bin/bash
set -e
in="${1:-file.txt}"
[ ! -f "$in" ] && { echo "$0 - File $in not found."; exit 1; }
while IFS= read -r file
do
echo "Copy $file ..."
done < "${in}"
What I actually want to achieve in the end is to read these lines, then issue cp command for first 20 or 30 or them, and then delete them from the file.txt and then do again same thing.
Upvotes: 0
Views: 428
Reputation: 140900
With readarray
you can easily read a count of lines of input at a time:
while readrray -n 20 -t lines; do
for line in "${lines[@]}"; do
echo "Copy $file ..."
done
done < "${in}"
Upvotes: 1