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 06-17-2004, 08: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, 03:36 PM   #2
keefaz
Senior Member
 
Registered: Mar 2004
Distribution: Slackware
Posts: 4,617

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


All times are GMT -5. The time now is 05:20 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration