Seach for a string following a particular string in a file | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

Seach for a string following a particular string in a file

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 10-16-2013
Anamika08 Anamika08 is offline
Registered User
 
Join Date: Oct 2013
Last Activity: 21 October 2013, 8:39 AM EDT
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
Seach for a string following a particular string in a file

All,
I have a file like ;

Code:
...  covers bhjl;
...  khkjhk..  covers vjgj;
.. bvjhy.. bkhk..  covers bjhk;

Now I want to search all strings that follows covers and then write them in a new file. I want to use perl script for that.

Output file should conatian:

Code:
bhjl
vjgj
bjhk

Regards
Anamika

Moderator's Comments:
Start using code tags as already asked for.

Last edited by zaxxon; 10-16-2013 at 07:38 AM.. Reason: code tags
Sponsored Links
    #2  
Old 10-16-2013
ctsgnb ctsgnb is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 22 September 2014, 5:35 AM EDT
Location: France
Posts: 2,929
Thanks: 80
Thanked 624 Times in 596 Posts
does "cover" always appear once per line ?
does "cover" always appear before the last word of the line ?
Sponsored Links
    #3  
Old 10-16-2013
Anamika08 Anamika08 is offline
Registered User
 
Join Date: Oct 2013
Last Activity: 21 October 2013, 8:39 AM EDT
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
yes..it will appear one in a line.

---------- Post updated at 04:33 AM ---------- Previous update was at 04:29 AM ----------

yes..it will appear once in a line and it will come just before the last word of that line. But there can be other lines that does not conatin cover. I do not have to do anything with them.
    #4  
Old 10-16-2013
ctsgnb ctsgnb is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 22 September 2014, 5:35 AM EDT
Location: France
Posts: 2,929
Thanks: 80
Thanked 624 Times in 596 Posts
Are you willing to also remove the ending semicolon ";" for the lines containing "cover" ?
Sponsored Links
    #5  
Old 10-16-2013
Anamika08 Anamika08 is offline
Registered User
 
Join Date: Oct 2013
Last Activity: 21 October 2013, 8:39 AM EDT
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
Yes.. It should be removed. I need only the word next to cover.
Sponsored Links
    #6  
Old 10-16-2013
ctsgnb ctsgnb is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 22 September 2014, 5:35 AM EDT
Location: France
Posts: 2,929
Thanks: 80
Thanked 624 Times in 596 Posts

Code:
sed '/cover/s/[ ]*;$//;s/.*cover //' yourfile

Sponsored Links
    #7  
Old 10-16-2013
Anamika08 Anamika08 is offline
Registered User
 
Join Date: Oct 2013
Last Activity: 21 October 2013, 8:39 AM EDT
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
Will it work for perl.. I want in perl...

---------- Post updated at 05:09 AM ---------- Previous update was at 05:07 AM ----------

Will it work for perl ???I want to run for perl in windows....
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
grep exact string from files and write to filename when string present in file JC_1 Shell Programming and Scripting 4 08-06-2012 10:52 PM
sed or awk command to replace a string pattern with another string based on position of this string vivek d r Shell Programming and Scripting 10 06-19-2012 09:35 AM
replace (sed?) a single line/string in file with multiple lines (string) from another file?? tuathan Shell Programming and Scripting 5 04-20-2011 12:16 AM
search string in a file and retrieve 10 lines including string line sukrish Shell Programming and Scripting 8 08-19-2010 03:53 PM
Seach for part of string and replace whole word stinnes UNIX for Dummies Questions & Answers 5 03-22-2010 09:11 AM



All times are GMT -4. The time now is 09:51 AM.