Help: Counting values less than a number


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help: Counting values less than a number
# 8  
Old 05-25-2016
Ah ha, this runs and reports the results as desired -- however, I would like it in a dat file rather than just printed to the screen, if possible. The only way I've done an awk to a file before is

Code:
awk 'insertawkcommandshere' > newfile.dat

but that enters an infinite loop with this; how do I fix that?
# 9  
Old 05-25-2016
The loop is not infinite. It ends when the last file is processed.

Code:
#!/bin/csh

rm -f new_file.dat

foreach file ( "`ls -1 | grep 'rmsd_protein_.*.dat' `" )
   awk '$2 < 3 {c++} END {sub(".*_", "", f); sub("[.].*", "", f); print f, c}' f=$file $file >> new_file.dat
end


Last edited by rdrtx1; 05-25-2016 at 04:04 PM..
# 10  
Old 05-25-2016
It certainly looks like it should work to me, but this creates an empty file and still prints the results to the screen instead..?

---------- Post updated at 02:02 PM ---------- Previous update was at 01:59 PM ----------

(additional note: I tried putting the "> data.dat" after the "f= $file $file" and then it at least filled in the data document rather than printing to the screen, but every new line overwrites the last line...)
# 11  
Old 05-25-2016
see corrected script.
# 12  
Old 05-25-2016
Eyyyy, perfect! Thanks!
# 13  
Old 05-25-2016
OK, with these requirements this is a version without a shell loop, which should run fairly quickly:
Code:
find . -name 'rmsd_protein_*.dat' -exec awk 'FNR==1{if(NR>1) print F[2],c; split(FILENAME,F,/.*_|[.]/); c=0} $2<3{c++}END{print F[2],c}' OFS='\t' {} + > newfile.dat

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Solved] Counting The Number of Lines Between Values with Multiple Variables

Hey everyone, I have a bunch of lines with values in field 4 that I am interested in. If these values are between 1 and 3 I want it to count all these values to all be counted together and then have the computer print out LOW and the number of lines with those values in between 1 and 3,... (2 Replies)
Discussion started by: VagabondGold
2 Replies

2. Shell Programming and Scripting

Counting the number of characters

Hi all, Can someone help me in getting the following o/p I/p:... (7 Replies)
Discussion started by: Sri3001
7 Replies

3. Shell Programming and Scripting

counting lines containing two column field values with awk

Hello everybody, I'm trying to count the number of consecutive lines in a text file which have two distinctive column field values. These lines may appear in several line blocks within the file, but I only want a single block to be counted. This was my first approach to tackle the problem (I'm... (6 Replies)
Discussion started by: origamisven
6 Replies

4. Shell Programming and Scripting

counting number of pattern occurrences

Hi All, Is it possible to count number of occurrences of a pattern in a single record using awk?? for example: a line like this: abrsjdfhafa I want to count the number of a character occurrences. but still use the default RS, I don't want to set RS to single character. (1 Reply)
Discussion started by: ghoda2_10
1 Replies

5. Shell Programming and Scripting

counting number of sentence

Hi all I want to count total numbers of sentences separated by fullstop (.) in different files under a directory at one go. Any help is appreciated. (3 Replies)
Discussion started by: my_Perl
3 Replies

6. Shell Programming and Scripting

Counting number of commas(,) in a variable

Hi all, I am having problems counting commas (,) from a variable in shell scripting.. the variable contains similiar to: ID@NAME@DESCRIPTION,ID@NAME@DESCRIPTION, ..... It can go on and on.. So i need to count the number of sets i.e.( ID@NAME@DESCRIPTION is one set) and process the... (4 Replies)
Discussion started by: faelric
4 Replies

7. Shell Programming and Scripting

counting the number of occurences

say i've got a text file with >10million sequences: ssss ssss tttttt uuuuuu uuuuuu uuuuuu ... I'd like to convert the file so that the output will report the number of occurence right by each sequence: 2 ssss 2 ssss 1 tttttt 3 uuuuuu 3 uuuuuu 3 uuuuuu .... (3 Replies)
Discussion started by: johjoh
3 Replies

8. Shell Programming and Scripting

counting the number of lines - again

Hi all, I use bash shell and I have a problem with wc. I would like to determine the number of lines in a file so I do wc -l filename but I don't want to get the filename again I just would like to have the number of lines and use it in a variable. Can anybody help? Thank you, (7 Replies)
Discussion started by: f_o_555
7 Replies

9. UNIX for Dummies Questions & Answers

Counting number of occurences

Hi All, I have to count the number of occurences of the character " ; " in a given line. I had used the following awk command to achieve the same echo $KOP.dat|awk '{split($1,my,";"); for(i in my)c++ }END{print c-1}' My file KOP.dat had the following data ... (1 Reply)
Discussion started by: kingofprussia
1 Replies

10. Linux

counting the number of lines

Hello, I have afile which begins with a few urls on multiple lines and then there is listing of some information on separate lines. The listing begins with the word Name on a given line followed by teh actual list. I want to count the number of lines in this file after the line having... (6 Replies)
Discussion started by: nayeemmz
6 Replies
Login or Register to Ask a Question