LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-11-2004, 10:25 AM   #1
barisdemiray
Member
 
Registered: Sep 2003
Location: Ankara/Turkey
Distribution: Slackware
Posts: 155

Rep: Reputation: 30
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!
 
Old 08-11-2004, 10:45 AM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
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
 
Old 08-11-2004, 12:42 PM   #3
barisdemiray
Member
 
Registered: Sep 2003
Location: Ankara/Turkey
Distribution: Slackware
Posts: 155

Original Poster
Rep: Reputation: 30
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! ;-)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash: read lines from a configuration script ldp Programming 2 09-23-2005 11:58 AM
[bash] removing or editing lines in file Erhnam Programming 12 03-15-2005 07:25 AM
shell script to copy lines from a file Warmduvet Programming 2 09-14-2004 09:25 PM
removing lines from file script iluvatar Programming 9 08-20-2004 05:49 AM
[bash] remove lines from a file Drimo Programming 3 03-20-2004 11:16 AM


All times are GMT -5. The time now is 06:06 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration