LinuxQuestions.org
Visit Jeremy's Blog.
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 12-02-2007, 10:19 AM   #1
horacioemilio
Member
 
Registered: Dec 2007
Posts: 61

Rep: Reputation: 15
Shell script to jump over lines


Hi,

I need to write a script that looks into a file for some special
string, and when it founds it then I need to jump to the NEXT line of
the file and read something. Afterwards, continue again the process
until we reach the end of the file.

My main problem is just to "jump" to the next line of the file. I do
not what strategy use.

Any help would be greatly appreciated
 
Old 12-02-2007, 10:28 AM   #2
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 97
Sounds like homework.

I would suggest setting a variable upon a successful search and testing the value of that veriable for the next line.

Please post the code that you have so far plus information about where you are getting stuck.

Please place tags around your code to preserve formatting.
 
Old 12-02-2007, 10:32 AM   #3
horacioemilio
Member
 
Registered: Dec 2007
Posts: 61

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Disillusionist View Post
Sounds like homework.

I would suggest setting a variable upon a successful search and testing the value of that veriable for the next line.

Please post the code that you have so far plus information about where you are getting stuck.

Please place tags around your code to preserve formatting.
Yes, but how can I test tje value of the variable for the next line ? This is difficult for me. The rest of the things are esay.
 
Old 12-02-2007, 10:36 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 741Reputation: 741Reputation: 741Reputation: 741Reputation: 741Reputation: 741Reputation: 741
Please tell us what your experience with scripting is--ie are you just starting, or have you done some coding?

One thing to look at is SED. Based on the criteria you give it, it can move to the next line.

Here's my favorite SED tutorial: http://www.grymoire.com/Unix/Sed.html
 
Old 12-02-2007, 10:38 AM   #5
horacioemilio
Member
 
Registered: Dec 2007
Posts: 61

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by pixellany View Post
Please tell us what your experience with scripting is--ie are you just starting, or have you done some coding?

One thing to look at is SED. Based on the criteria you give it, it can move to the next line.

Here's my favorite SED tutorial: http://www.grymoire.com/Unix/Sed.html
I am starting to learn now. But I know C++ well and some other very basic shell things.
 
Old 12-02-2007, 10:53 AM   #6
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 741Reputation: 741Reputation: 741Reputation: 741Reputation: 741Reputation: 741Reputation: 741
Wow--anyone can learn C++ should have no trouble learning BASH. One good trick is to go to http://tldp.org and download the "Advanced BASH scripting guide" Put it in a convenient place and use it for searches. (Print it at your own risk....)
 
Old 12-02-2007, 10:57 AM   #7
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 97
Quote:
Originally Posted by pixellany View Post
Please tell us what your experience with scripting is--ie are you just starting, or have you done some coding?

One thing to look at is SED. Based on the criteria you give it, it can move to the next line.

Here's my favorite SED tutorial: http://www.grymoire.com/Unix/Sed.html
Nice tutorial, do you have a good awk tutorial as well?
 
Old 12-02-2007, 11:01 AM   #8
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 741Reputation: 741Reputation: 741Reputation: 741Reputation: 741Reputation: 741Reputation: 741
Quote:
Originally Posted by Disillusionist View Post
Nice tutorial, do you have a good awk tutorial as well?
That same site has all manner of Unix tutorials--including awk

http://www.grymoire.com/Unix
 
Old 12-02-2007, 05:44 PM   #9
PAix
Member
 
Registered: Jul 2007
Location: United Kingdom, W Mids
Distribution: SUSE 11.0 as of Nov 2008
Posts: 195

Rep: Reputation: 40
To clarify please:


Given an input file as shown below, with a which is looking for a special string of "and", which is the correct output you want to see? Example A or B?
Quote:
but, more importantly, they are an outward
representation of Macbeths inner evil. Having said
this, the brooding and mystifying darkness itself is
recurring motif in the drama and, like the witches,
it symbolizes the darkness in Macbeths heart
and the evil nature of his horrible deeds.
Quote:
A
but, more importantly, they are an outward
representation of Macbeths inner evil. Having said
it symbolizes the darkness in Macbeths heart
Quote:
B
but, more importantly, they are an outward
representation of Macbeths inner evil. Having said
this, the brooding
recurring motif in the drama
it symbolizes the darkness in Macbeths heart
Sed or awk seem favourites in my book, but if you don't specify a problem properly, how can you expect anyone else to arrive at a correct answer. It happens all too often when users come to you with a problem.

Last edited by PAix; 12-02-2007 at 05:52 PM.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script for comparing certain lines in two files mou5e Linux - Newbie 9 06-06-2007 01:40 PM
insert lines in a function using shell script shyamdey Programming 1 08-30-2006 07:48 AM
shell script for expanding lines in a file b123coder Programming 1 05-25-2006 04:51 AM
shell script to copy lines from a file Warmduvet Programming 2 09-14-2004 09:25 PM

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

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