The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
read a file line by line chebarbudo Shell Programming and Scripting 8 11-26-2008 02:00 PM
Read a file line by line VENC22 UNIX for Dummies Questions & Answers 4 10-30-2008 11:09 AM
read a file line by line in ksh chella Shell Programming and Scripting 3 08-29-2008 01:57 AM
read the file line by line kittusri9 Shell Programming and Scripting 3 04-24-2008 08:26 AM
How to read from a file line by line and do stuff spaceship Shell Programming and Scripting 4 03-17-2005 09:47 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-15-2009
madi3d8 madi3d8 is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 1
Post I need suggestion on problem read a file line by line and do stuff

At first, give my best wish for all MOD and admins here. I"m learning bash shell program just for a month, not too much, not too little, but i must admire that i'm very bad at math and algorithm.

I want to do this :
Read the content of a file line by line and at each line, ask me want to read next line or not, if not, press N - end, if yes, press Y - read next line

This is the content of file :
Code:
I love linux verymuch. I want to learn it
Bash shell is not hard but it make
me gonna crazy. Can any one help me
...
I very need suggestion, i know it very easy with somebody else but with me it's not easy to find out.
  #2 (permalink)  
Old 01-15-2009
vbe's Avatar
vbe vbe is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2005
Location: Switzerland - GE
Posts: 1,569
Presented like that, it looks like homework... (Do you remember the rules?...)
If I were you I would start by writing on a paper what is to be done:
In other words the algorithm...
Then once satisfied with it translate it to shell script.
Only at this point if it is not satifactory should I ask what we think of the script my posting a thread, explaining us your frustration with your code

And sure you will have replies...

Courage!
  #3 (permalink)  
Old 01-15-2009
angheloko's Avatar
angheloko angheloko is offline
Registered User
  
 

Join Date: Jul 2008
Location: Philippines
Posts: 125
Ooppss...Had to edit it...

So here are some tips

Use cat, while, read...

Then you'll probably encounter something weird like not being able to enter your choice of y/n so try searching about tty

Last edited by angheloko; 01-15-2009 at 11:25 AM.. Reason: Looks like homework
  #4 (permalink)  
Old 01-15-2009
Ikon's Avatar
Ikon Ikon is offline Forum Advisor  
Registered User
  
 

Join Date: Jul 2008
Location: Phoenix, Arizona
Posts: 669
Heres some hints:

This
Code:
for line in `cat /path/to/yourfile`; do
    echo $line
    {do something}
done

Then lookup the read command.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:13 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0