Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Search a wildcard text in a file

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 10-15-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
Search a wildcard text in a file

Hi,
I have a file(report.txt) that contains :

Code:
0        1      chk_uncov_data_assert          776   chk_uncov_data_assert : assert property (chk_uncov_data) 
1        0      chk_data_assert                772   chk_data_assert : assert property (chk_data) 
1        0      chk_data_cover                 770   chk_data_cover : cover property (chk_data); 
my_test_base.m_my_env.m_my_agent.ap.uvm_port_base::m_if.m_imp.write_data 100%, 100% (2/2)               400   covergroup write_data;         
my_test_base.m_my_env.m_my_agent.ap.uvm_port_base::m_if.m_imp.unwrite_data 0%, 0% (0/1)                   409   covergroup unwrite_data;

Now In another file(new.txt) , I want to print all words in seperate line that contain string "_assert". I want a perl program for this.

Output should be ;


Code:
chk_uncov_data_assert
chk_data_assert

Regards,
Anamika

Last edited by Don Cragun; 10-15-2013 at 12:54 PM.. Reason: Added CODE tags
Sponsored Links
    #2  
Old Unix and Linux 10-15-2013
pravin27 pravin27 is offline Forum Advisor  
Advisor
 
Join Date: Sep 2009
Last Activity: 26 June 2015, 3:24 AM EDT
Location: ./India/Bangalore
Posts: 1,237
Thanks: 58
Thanked 283 Times in 276 Posts
Here you go

Code:
perl -nle 'BEGIN{$/=" ";} { print if (/_assert/ && !$seen{$_}++)}' filename

Please use code tag for your code while posting
Sponsored Links
    #3  
Old Unix and Linux 10-15-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
Hi Pravin,
Thanx for the reply. But it is showing error as :
can's find the string terminator "'" anywhere before EOF at -e line 1.

This ' is which symbol? The one that is before 1 key of keyboard or that is near enter key????
    #4  
Old Unix and Linux 10-15-2013
itkamaraj's Unix or Linux Image
itkamaraj itkamaraj is offline Forum Advisor  
^Kamaraj^
 
Join Date: Apr 2010
Last Activity: 25 June 2015, 3:24 AM EDT
Posts: 3,060
Thanks: 34
Thanked 661 Times in 640 Posts

Code:
$ cat test.txt
0 1 chk_uncov_data_assert 776 chk_uncov_data_assert : assert property (chk_uncov_data)
1 0 chk_data_assert 772 chk_data_assert : assert property (chk_data)
1 0 chk_data_cover 770 chk_data_cover : cover property (chk_data);
my_test_base.m_my_env.m_my_agent.ap.uvm_port_base::m_if.m_imp.write_data 100%, 100% (2/2) 400 covergroup write_data;
my_test_base.m_my_env.m_my_agent.ap.uvm_port_base::m_if.m_imp.unwrite_data 0%, 0% (0/1) 409 covergroup unwrite_data; 


$ perl -lane 'print $F[2] if ($_=~/_assert/)' test.txt
chk_uncov_data_assert
chk_data_assert

Sponsored Links
    #5  
Old Unix and Linux 10-15-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
I am getting same error ;
can't find the string terminator " ' " any where before EOF at -e line 1.
Sponsored Links
    #6  
Old Unix and Linux 10-15-2013
itkamaraj's Unix or Linux Image
itkamaraj itkamaraj is offline Forum Advisor  
^Kamaraj^
 
Join Date: Apr 2010
Last Activity: 25 June 2015, 3:24 AM EDT
Posts: 3,060
Thanks: 34
Thanked 661 Times in 640 Posts
if you are running the perl in your windows machine. Then try the below


Code:
perl -lane "print $F[2] if ($_=~/_assert/)" test.txt

The Following User Says Thank You to itkamaraj For This Useful Post:
Anamika08 (10-15-2013)
Sponsored Links
    #7  
Old Unix and Linux 10-15-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

Code:
perl -nle 'BEGIN{$/=" ";} { print if (/_assert/ && !$seen{$_}++)}' filename

And if I am giving perl -nl `BEGIN($/+" " ;{}print if (/_assert/ &&!$seen{$_}++)}' test.txt
Then it gives error:

Code:
Can't open perl script "`BEGIN($/+ ;}{print": No such file or directory..

Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Grep Wildcard search venky338 Shell Programming and Scripting 2 02-16-2012 06:37 PM
search text file in file if this file contains necessary text (awk,grep) candyme Shell Programming and Scripting 4 04-20-2011 10:04 AM
how to search and list file with wildcard character anandapani UNIX for Dummies Questions & Answers 2 06-27-2010 11:08 PM
Search text from a file and print text and one previous line too kamranjalal Shell Programming and Scripting 6 01-06-2009 02:27 AM
search and replace a specific text in text file? santosham UNIX for Dummies Questions & Answers 4 06-25-2008 05:53 PM



All times are GMT -4. The time now is 10:30 PM.