LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 06-17-2004, 07:59 AM   #1
isl01jbe
LQ Newbie
 
Registered: May 2004
Distribution: Slackware
Posts: 11

Rep: Reputation: 0
bash-script: output text between two ocurrences of a specific string


I'm using a bash-script to search trough a couple of directories. if a specific string is found within one of the files, i want to output the text between two occurrences of the string DESCRIPTION. i guess one can grep or sed it, but my skills are a bit limited.

How would you go about solving this?

/Jonas
 
Old 06-17-2004, 02:36 PM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
for a directory :
Code:
string="your string to search"

for file in /a/directory/*; do
    if grep -i $string $file; then
        findText=$(cat $file | awk -F "DESCRIPTION" '{print $2;}')
        echo "Text found in $file ! : $findText"
    fi
done

Last edited by keefaz; 06-17-2004 at 02:43 PM.
 
  


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
How to replace string pattern with multi-line text in bash script? brumela Linux - Newbie 6 04-21-2011 06:56 AM
How to find and change a specific text in a text file by using shell script Bassam Programming 1 07-18-2005 07:15 PM
Send string to std output without interpreting (script) ta0kira Programming 6 06-29-2005 08:50 AM
script for changing a specific string in a directory irfanhab Programming 5 06-28-2005 01:27 PM
Bash Script String Splitting MurrayL Linux - Newbie 1 09-21-2004 03:20 AM

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

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