Perl: Search and print help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl: Search and print help
# 1  
Old 09-30-2008
Perl: Search and print help

Hi all,

I need a bit of help with a perl script,

I have a file containing lines that look like:

M1 (Agnd Agnd ibias_gnP Agnd) nch l=250.0n w=10u m=1 ad=2.5e-12 \
as=2.5e-12 pd=20.5u ps=20.5u nrd=0.025 nrs=0.025 sa=2.5e-07 \
sb=2.5e-07
M21 (Agnd VSSabc Agnd Agnd) nch l=250.0n w=10u m=12 ad=1.83333e-12 \
as=1.83333e-12 pd=13.7u ps=13.7u nrd=0.0183333 nrs=0.0183333 \
sa=5.52857e-07 sb=5.52857e-07
M18 (Agnd Vddxyz ibias_eqN Agnd) nch l=250.0n w=10u m=1 ad=2.5e-12 \
as=2.5e-12 pd=20.5u ps=20.5u nrd=0.025 nrs=0.025 sa=2.5e-07 \
sb=2.5e-07
M0 (Agnd Agnd net133 Agnd) nch l=250.0n w=10u m=1 ad=2.5e-12 \
as=2.5e-12 pd=20.5u ps=20.5u nrd=0.025 nrs=0.025 sa=2.5e-07 \
sb=2.5e-07
M32 (net120 VDDcde ibias_gnN Agnd) nch l=250.0n w=10u m=7 ad=1.64286e-12 \
as=1.64286e-12 pd=11.7571u ps=11.7571u nrd=0.0164286 nrs=0.0164286 \
sa=1.06144e-06 sb=1.06144e-06
M8 (Agnd Agnd ibias_eqP Agnd) nch l=250.0n w=10u m=1 ad=2.5e-12 \
as=2.5e-12 pd=20.5u ps=20.5u nrd=0.025 nrs=0.025 sa=2.5e-07 \
sb=2.5e-07


I need the script to search for Agnd or VSS or Vss or vss or VDD or Vdd or vdd in the second position (ie the gate) inside the bracket.
in other words

M32 (net120 VDDcde ibias_gnN Agnd) => match
M42 (net120 net20 ibias_gnN Agnd) => no match
When a match is found it needs to print off the line to a file
# 2  
Old 09-30-2008
Code:
print if m/\(\S+\s+(Agnd|V(SS|ss|DD|dd))\s/

# 3  
Old 09-30-2008
seeing that they all appear in column 3,
Code:
awk '$3~/Agnd|V(SS|ss|DD|dd)/' file

likewise, in Perl, split the line, get item 3 and compare with the regex
# 4  
Old 09-30-2008
Thanks guys. much appreciated Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Search file and print everything except multiple search terms

I'm trying to find a way to search a range of similar words in a file. I tried using sed but can't get it right:sed 's/\(ca01\)*//'It only removes "ca01" but leaves the rest of the word. I still want the rest of the information on the lines just not these specific words listed below. Any... (3 Replies)
Discussion started by: seekryts15
3 Replies

2. Shell Programming and Scripting

Perl - start search by using search button or by pressing the enter key

#Build label and text box $main->Label( -text => "Input string below:" )->pack(); $main->Entry( -textvariable => \$text456 )->pack(); $main->Button( -text => "Search", -command => sub { errchk ($text456) ... (4 Replies)
Discussion started by: popeye
4 Replies

3. Shell Programming and Scripting

Search between two search strings and print the value

Based on the forums i have tried with grep command but i am unable to get the required output. search this value /*------ If that is found then search for temp_vul and print and also search until /*------- and print new_vul Input file contains: ... (5 Replies)
Discussion started by: onesuri
5 Replies

4. Shell Programming and Scripting

Perl - use search keywords from array and search a file and print 3rd field when matched

Hi , I have been trying to write a perl script to do this job. But i am not able to achieve the desired result. Below is my code. my $current_value=12345; my @users=("bob","ben","tom","harry"); open DBLIST,"<","/var/tmp/DBinfo"; my @input = <DBLIST>; foreach (@users) { my... (11 Replies)
Discussion started by: chidori
11 Replies

5. Shell Programming and Scripting

Search and print in Unix

Hi All I have two files name file1 and file2 The date present in file1 is aaaa ssss dddd ffff qqqq wwww eeee and the data present in file2 is aaaa 1 2 3 4 ssss 3 5 6 7 dddd 1 2 qqqq 1 6 y 9 (10 Replies)
Discussion started by: parthmittal2007
10 Replies

6. Shell Programming and Scripting

pattern search and print using sh

Hi All, Have a file contains multiple line with the following file.txt insert: akdkas job:ksdjf command: aldfasdf asdfsdfa asdfas.sh machine: asdfa need to grep for insert and machine and print only "akdkas,asdfa" cat file.txt | egrep "insert|machine" | awk -F: '{print $2}' output ... (5 Replies)
Discussion started by: uniqme
5 Replies

7. Shell Programming and Scripting

perl search and replace - search in first line and replance in 2nd line

Dear All, i want to search particular string and want to replance next line value. following is the test file. search string is tmp,??? ,10:1 "???" may contain any 3 character it should remain the same and next line replace with ,10:50 tmp,123 --- if match tmp,??? then... (3 Replies)
Discussion started by: arvindng
3 Replies

8. Shell Programming and Scripting

Perl :How to print the o/p of a Perl script on console and redirecting same in log file @ same time.

How can i print the output of a perl script on a unix console and redirect the same in a log file under same directory simultaneously ? Like in Shell script, we use tee, is there anything in Perl or any other option ? (2 Replies)
Discussion started by: butterfly20
2 Replies

9. Shell Programming and Scripting

awk search and print

I have a script where I need to use awk, go through some output, which is stored in a variable, and find a string Xms and Xmx and print the results, including the rest of that string. Example of string: ... (3 Replies)
Discussion started by: cbo0485
3 Replies

10. Shell Programming and Scripting

Perl: Search for string on line then search and replace text

Hi All, I have a file that I need to be able to find a pattern match on a line, search that line for a text pattern, and replace that text. An example of 4 lines in my file is: 1. MatchText_randomNumberOfText moreData ReplaceMe moreData 2. MatchText_randomNumberOfText moreData moreData... (4 Replies)
Discussion started by: Crypto
4 Replies
Login or Register to Ask a Question