LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-12-2003, 06:10 AM   #1
amaze
LQ Newbie
 
Registered: Aug 2003
Location: UK
Posts: 19

Rep: Reputation: 0
Loop over lines in text file?


Hi,

I have a generated text file which looks like this (see below):

87.123.231.21 MANCHESTER
87.123.231.27 LONDON
87.123.231.28 GLASGOW

...I need to loop over EACH line (I can access each col..) but I can't figure out a way to do this in BASH scripting.

Can anyone tell me the syntax?

Thanks
 
Old 08-12-2003, 06:40 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
cat <text> | while read line; do
#split space separated to array
line=( ${line} )
echo -n "${line[0]}" # This is the IP address
echo "${line[1]}" # This is the City
done
 
Old 08-12-2003, 07:15 AM   #3
amaze
LQ Newbie
 
Registered: Aug 2003
Location: UK
Posts: 19

Original Poster
Rep: Reputation: 0
Works great thanks very much!
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Grab text lines in text file LULUSNATCH Programming 1 12-02-2005 10:55 AM
adding text to lines in a file tpreitano Linux - General 2 10-04-2005 09:30 AM
Remove odd lines from a text file Mr. Gone Programming 2 09-19-2005 11:16 AM
Python - Set vars and loop over lines in file jnoller Programming 6 02-07-2004 10:32 AM
How to filter lines from a text file Rascale Linux - Software 1 10-28-2003 12:46 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration