Skip to content

Run the same command on every line in a file

This snippet will let you run the same command using each line from a file as a parameter.

cat filename.txt | while read in; do echo "$in"; done

As written it’ll open up filename.txt and echo out every line. Probably not what you want, so replace echo “$in” with whatever command you want to run. The $in variable is the line it’s pulling out of the file.

What I needed this for was to block a bunch of IP addresses that were hitting honeypot files on a server so instead of echo I was running csf to add the IP.

Published inCode Tips

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *