Browse > Home / Archive: 23. March 2005

| Subcribe via RSS

read a file with bash

March 23rd, 2005 | 60 Comments | Posted in Bash, Simple Tips

I'm going to try to post a few howto articles for some of the simpler tasks. Many of these will be things that I use daily.

It is often necessary to read a file with bash, and act upon the entire line. There are many different ways to do this, but I'll outline two of the simpler methods, both suitable for stacking on a single command line.

For this exercise I'll assume the file is a list of files that we need to execute a command on.

# cat file.lst |while read line; do echo "${line}"; done /tmp/file1.txt /tmp/file with space.txt #

More »