LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Can't get lines of a file with a Bash script.. (https://www.linuxquestions.org/questions/programming-9/cant-get-lines-of-a-file-with-a-bash-script-216224/)

barisdemiray 08-11-2004 10:25 AM

Can't get lines of a file with a Bash script..
 
Hi! I'm working on a Bash shell script but i've stucked at one point. I have a code like below

Code:

...
for phrase in `cat $PHRASE_REPOSITORY/$phrasedir/weighted.tmp`; do
...

Don't think about variables, they're only directory names. But the problem is this: Since weighted.tmp file contains phrases like

Code:

one two
three four five

when i grab the cated values into `phrase' variable it takes the values "one", "two", "three", "four" seperately. How can i get the file data line by line? Is there any commands that match only newlines, not all printable spaces? Thanks!

Dark_Helmet 08-11-2004 10:45 AM

A quick way is to change your IFS variable. Try this:
Code:

#!/bin/bash

old_ifs=$IFS
IFS=$'\n'
...
for phrase in `cat $PHRASE_REPOSITORY/$phrasedir/weighted.tmp`; do
...
IFS=$old_ifs


barisdemiray 08-11-2004 12:42 PM

Quote:

Originally posted by Dark_Helmet
A quick way is to change your IFS variable. Try this:
Code:

#!/bin/bash

old_ifs=$IFS
IFS=$'\n'
...
for phrase in `cat $PHRASE_REPOSITORY/$phrasedir/weighted.tmp`; do
...
IFS=$old_ifs


That was really cool and works great! So much thanks Dark_Helmet! ;-)


All times are GMT -5. The time now is 03:03 PM.