LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-18-2014, 02:32 PM   #1
hoi
LQ Newbie
 
Registered: Jun 2013
Posts: 27

Rep: Reputation: Disabled
read multiple line from file in bash


Content of myfile.txt:
1 1 1 1
1 1 2 2

code:
read a b c d < myfile.txt
echo $a
echo $b
echo $c
echo $d

output:
1
1
1
1

How to read many line from file one by one??
 
Old 04-18-2014, 02:40 PM   #2
hoi
LQ Newbie
 
Registered: Jun 2013
Posts: 27

Original Poster
Rep: Reputation: Disabled
got answer..
cat file | while read a b c d
do
echo $a
echo $b
echo $c
echo $d
done
 
Old 04-19-2014, 02:16 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,245

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Try doing the following after the loop:
Code:
echo $a
See if you get what you think you should?
 
Old 04-19-2014, 02:28 AM   #4
kooru
Senior Member
 
Registered: Sep 2012
Posts: 1,385

Rep: Reputation: 273Reputation: 273Reputation: 273
Code:
while read line
do
echo $line
done < file
 
  


Reply

Tags
bash script $@, bash scripting, linux command, shell script, shell scripting


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 shell script read file line by line. Darren[UoW] Programming 57 04-17-2016 07:07 PM
[bash] Read file line by line and split on whitespace tskuzzy Programming 4 07-06-2009 04:24 PM
bash : read every line from text file starting at given line number quadmore Programming 4 02-20-2009 01:29 PM
I would like need a suggestion on bash shell : Read a file line by line and do stuff madi3d8 Linux - Newbie 1 01-15-2009 10:30 AM


All times are GMT -5. The time now is 10:02 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration