Tag archive for: shell scripting

How to loop through lines of text in a text file from a shell script dynamically

There are times when we need to dynamically run shell commands based on the items listed in a text file.

The shell script that I ran in my bash shell does the following:
for each line separated by newline and not preceded by a ‘#’ character, print the line to console.

In order to build the shell script, I would need the following code pieces:

  • A way to remove/delete empty lines or leading and trailing whitespace in a text file
  • A way to loop through the text file, line by line
  • A way to check if the first character of the string

This post documents what I had ran in my bash shell (in Ubuntu 14.0.4) to loop through items separated by newlines in a text file.