how many pass in the file ,three question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how many pass in the file ,three question
# 1  
Old 03-16-2010
how many pass in the file ,three question

Quote:
$cat file

abcd
FINISH
DFDFDFDFDF
789
PASS
PASS
PASS
FINISH
PASS
FINISH
12345
PASS
PASS
Hi all
Question 1:
I want to use "awk" or "sed" to know how many "PASS after "FINISH"
i
Question 2:
I want to use "awk" or "sed" to know how many "PASS" after the *last* "FINISH ,it shoud be 2 in this file

Question 3.
I want to use "awk" or "sed" to know how many "PASS between "789" and "12345"

Thanks for your help
# 2  
Old 03-16-2010
MySQL

See the following commands.

Ans1:


Code:
grep -c "PASS" fine_name

Code:
 sed -n '/PASS/p' fine_name | wc -l



Ans2:
Code:
cat fine_name | tr "\n" " " | sed -r "s/(.*) (FINISH.*)/\2/g" | tr " " "\n" | grep -c "PASS"




Ans3:

Code:
sed -n '/789/,/12345/p' fine_name | grep -c "PASS"


Last edited by ungalnanban; 03-16-2010 at 01:47 AM..
# 3  
Old 03-16-2010
Thanks for the quick answer. for the first one, I want to know how many "PASS" after FINISH, you tell me total num of PASS in the file
# 4  
Old 03-16-2010
MySQL

See the following code. to count the total number of "PASS" after matching the first occurrence of the "FINISH"


Code:
sed -n '/FINISH/,$p' pass | grep -c "PASS"

# 5  
Old 03-16-2010
Using awk,

Code:
awk '/PASS/ &&  c++ && 0 END { print c; }' file

awk '/FINISH/ { f=1 } /PASS/ && f++ && 0 END { print f-1; }' file

awk '/789/,/12345/ { if(/PASS/) {c++;} }END { print c }' file

# 6  
Old 03-16-2010
change the file with awk and sed

thanks all

Last edited by yanglei_fage; 03-16-2010 at 01:08 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Trying to take file numbers from a file, pass them to sed to change strings in corresponding lines

I have a bunch of file numbers in the file 'test': I'm trying the above command to change all the instances of "H" to "Na+" in the file testsds.pdb at the line numbers indicated in the file 'test'. I've tried the following and various similar alternatives but nothing is working: cat test |... (3 Replies)
Discussion started by: crunchgargoyle
3 Replies

2. Shell Programming and Scripting

Question about sorting -- how to pass an array to a function

Hi, guys I just wanted to sort the elements of an array ascendingly. I know the following code does work well: array=(13 435 8 23 100) for i in {0..4} do j=$((i+1)) while ] do if } -le ${array} ]] then : else min=${array} ${array}=${array} ${array}=$min fi... (5 Replies)
Discussion started by: franksunnn
5 Replies

3. Shell Programming and Scripting

Perl - pass file to subroutine

Hello All, I have 2 perl sub-routines. my $myDir = myDir_path; my $file; sub convert(){ system ("./$myConvertScript >> $myDir/$file_CONV" ); $file2 = $myDir/$file_CONV; } sub addDB(){ open(CONF, $config) or die "Cannot Open $config for reading. "; while(<CONF>){... (1 Reply)
Discussion started by: ad23
1 Replies

4. Shell Programming and Scripting

Pass value from file to parameter

Hi Guys, I have a file in the format Parmater=value. I want to read the value and pass it to corresponding Variable. The Parameter file is as follows Number=23 Text1=mango Text2=yup 'Number' value needs to be read and passed to ID variable. Also, 'Text1' value needs to be passed to... (9 Replies)
Discussion started by: mac4rfree
9 Replies

5. Shell Programming and Scripting

I have to pass a sentence in a file,

I have to pass a sentence in a file, the specs are as: cat run | sed 's/SRT/'$8'/g' | sed 's/plength/68/g' | sed 's/stcol/'$5'/g' | sed 's/encol/'$6'/g' | sed 's/brdtype/'$1'/g' | sed's/brdtxt/'$3'/g' | sed 's/demotxt/Total '$2'/g' | sed 's/bantxt/ban_'$7'/g' | sed 's/validcodes/'$4'/g' > runx ... (1 Reply)
Discussion started by: patilrakesh1984
1 Replies

6. Shell Programming and Scripting

How to pass parameters to an awk file?

I have an awk file where I need to pass a filename and a value as a parameter from a sh script. I need to know how to pass those values in the sh script and how to use the same in the awk file. Thanks in advance!!! Geetha (3 Replies)
Discussion started by: iamgeethuj
3 Replies

7. Shell Programming and Scripting

how to read a value from a file and pass it to a variable

Hi, Some one please help me with this script. I have a file "sequence.txt" and contents of it look like below. 1 5 3 7 4 7 5 74 from my script i should be able to read every single and save the first columnbs to variable x1, x2, x3 and second column as y1, y2, y3 and so on. Then i can... (3 Replies)
Discussion started by: pragash_ms
3 Replies

8. Shell Programming and Scripting

how do I pass or read values from file ?

Hi one & All , My Need is to Create 64 Partition and create File System in Linux. I have the Script ... for((a=0;a<=63;a++)) do fdisk /dev/cciss/c0d$a done for((a=0;a<=63;a++)) do mkfs.ext2 /dec/cciss/'c0d'$a'p1' done the moment I run the Script I get the Prompt ... Command... (1 Reply)
Discussion started by: nix-kid
1 Replies

9. Shell Programming and Scripting

reading from a file and pass as variables and ignore # in the file

file.txt contains ------------------ sat1 1300 #sat2 2400 sat3 sat4 500 sat5 I need to write a shell script that will output like the below #output sat1.ksh 1300 sat3.ksh sat4.ksh 500 sat5.ksh my try ------- (4 Replies)
Discussion started by: konark
4 Replies

10. Shell Programming and Scripting

getting the file name and pass as variable

Can any one suggest me how to check the file extension and pass the name based out of the filename within the folder. There would be always one latest file in the folder, but extension may vary... ie .csv, .CSV,.rpt,.xls etc what is best way to get the latest file name and pass as variable.... (1 Reply)
Discussion started by: u263066
1 Replies
Login or Register to Ask a Question