Hi,
I have a file(report.txt) that contains :
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 ;
chk_uncov_data_assert
chk_data_assert
Regards,
Anamika
Here you go
perl -nle 'BEGIN{$/=" ";} { print if (/_assert/ && !$seen{$_}++)}' filename
Please use code tag for your code while posting
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????
$ 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
I am getting same error ;
can't find the string terminator " ' " any where before EOF at -e line 1.
if you are running the perl in your windows machine. Then try the below
perl -lane "print $F[2] if ($_=~/_assert/)" test.txt
1 Like
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:
Can't open perl script "`BEGIN($/+ ;}{print": No such file or directory..
Hi,
I have a file a.log which contains :
1
1
0
Another file b.log as:
0
0
1
Another file c.log as ;
7%
22%
5%
Then I have an already existing excel file result.xls with some contents. I want to write a perl script that will open that excel sheet and then write contents of a.log in cell C2,C3,C4 . Then write contents of b.log in cell C7,C8,C9. And contents of c.log in cell C15,C16,C17. That is, Column will be same only row will change .
There can be any number of entries in a.log,b.log and c.log. Here I have taken only 3 entries.
The already written contents of excel sheet should not be affected.
It means i have to write contents of a log file to in a cell of an excel sheet. then column will be same only the row will increase.