Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 06-17-2004, 07:59 AM   #1
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?

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

Rep: Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724
for a directory :
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"

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


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 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 > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:24 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration