LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 10-11-2004, 02:43 PM   #1
saiz66
Member
 
Registered: Apr 2003
Posts: 225

Rep: Reputation: 30
[c shell] printing out each line in a file


Hi. I want to know how to print out each line in a file. Thanks!
 
Old 10-11-2004, 02:55 PM   #2
m00t00
Member
 
Registered: Sep 2004
Distribution: Slackware 10, Gentoo
Posts: 292

Rep: Reputation: 30
cat file

where file is the file you want to look at.
Or use a pager.

less file
or
more file
or (if you have it)
most file
 
Old 10-11-2004, 03:27 PM   #3
saiz66
Member
 
Registered: Apr 2003
Posts: 225

Original Poster
Rep: Reputation: 30
sorry.. i wanted to print out each line of a file and save it into a variable so if i had a file with a word on each line:

monday is yesterday.
tuesday is today.
wednesday is tomorrow.

i want to put each of these lines into a variable...

e.g.
variable = monday is yesterday.
and so on putting each of the lines into that or a different variable.

how would i do that?

Last edited by saiz66; 10-11-2004 at 06:00 PM.
 
Old 10-11-2004, 11:57 PM   #4
MrBrain
LQ Newbie
 
Registered: Oct 2004
Posts: 6

Rep: Reputation: 0
Code:
#!/bin/bash

#list the file into an variable
foo=$(cat your_file) 
for var1 in $foo
do
        #do something with the result...
        #....
        #echo "current line from file:" $var1
done
Something like this perhaps.
 
Old 10-12-2004, 08:15 AM   #5
saiz66
Member
 
Registered: Apr 2003
Posts: 225

Original Poster
Rep: Reputation: 30
that is just perfect! thanks!
 
  


Reply



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
unix shell script:How to delete the first line in a file?? rche3252 Programming 6 03-03-2010 07:32 AM
Print line number X of a file (in shell) rheza Programming 4 01-04-2005 05:55 PM
Shell script - how to show a specific line of a text file davi_cabral Linux - Software 3 09-28-2004 01:39 PM
How to delete a line from a text file with shell script programming Bassam General 1 01-28-2004 08:51 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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