LinuxQuestions.org
Visit Jeremy's Blog.
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, 01:32 PM   #1
hoi
Member
 
Registered: Jun 2013
Posts: 32

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, 01:40 PM   #2
hoi
Member
 
Registered: Jun 2013
Posts: 32

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, 01:16 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

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

Rep: Reputation: 275Reputation: 275Reputation: 275
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 06:07 PM
[bash] Read file line by line and split on whitespace tskuzzy Programming 4 07-06-2009 03:24 PM
bash : read every line from text file starting at given line number quadmore Programming 4 02-20-2009 12: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 09:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:31 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