Created
February 15, 2012 03:01
-
-
Save bluegraybox/1832793 to your computer and use it in GitHub Desktop.
Bash 'for' loop over lines, not words
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Only split on newlines, so each line of data is one record. | |
default_IFS=$IFS | |
IFS="$(echo -e "\n\r")" | |
# each $line will be one line, even if there are spaces in it. | |
for line in $(cat sample_data.txt) ; do | |
# do stuff... | |
done | |
# Restore default | |
IFS=$default_IFS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment