Greping frequency for list of phrases is a separate file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Greping frequency for list of phrases is a separate file
# 8  
Old 02-19-2014
what I get is
Code:
               books   cooking skills  house pet       flowers
john     20       1               0               1               0
mark    32       2               0               0               2

which is the number of the words in that file
but what I would like is
Code:
        books   cooking skills  house pet       flowers        count
john    1               0               1               0              2
mark    2               0               0               2             4

# 9  
Old 02-19-2014
Apply these changes:
Code:
        END {
                printf "\t"
                for ( k in P )
                        printf "%s\t", k
                printf "\tCount\n"

                for ( j in F )
                {
                        printf "%s\t", j
                        for ( k in P )
                        {
                                i = j FS k
                                if ( i in R )
                                {
                                        printf "%s\t\t", R[i]
                                        c += R[i]
                                }
                                else
                                        printf "%s\t\t", "0"
                        }
                        printf "%s\n", c
                        c = 0
                }
        }
' phrases mark john

Output:
Code:
        books   cooking skills  house pet       flowers         Count
john    1               0               1               0               2
mark    2               0               0               2               4

This User Gave Thanks to Yoda For This Post:
# 10  
Old 02-19-2014
somehow i get number of lines for each file has next to the name so when my data is being added it gets added to that number and I dont know how to delete that
e.g.
Code:
                  books   cooking skills  house pet       flowers       Count
john   20          1               0               1               0               22
mark  10          2               0               0               2               14

my exact code is as following
Code:
#!/bin/bash
mkdir results
FFILES="People/*"
for U in $FFILES
do
 docU=$(basename $U)
 docpathU=$(dirname $U)
 awk '
        NR == FNR {
                P[$0]
                next
        }
        {
                if ( ! ( FILENAME in F ) )
                        F[FILENAME]

                for ( k in P )
                {
                        if ( $0 ~ k )
                        {
                                R[FILENAME FS k]++
                        }
                }
        }
END {
                printf ","
                for ( k in P )
                        printf "%s,", k
                printf "Count\n"

                for ( j in F )
                {
                        printf "%s,", j
                        for ( k in P )
                        {
                                i = j FS k
								if ( i in R )
                                {
                                        printf "%s,", R[i]
                                        c += R[i]
                                }
                                else
                                        printf "%s,", "0"
                        }
                        printf "%s\n", c
                        c = 0
                }
        }
' accept-list.txt $U > result/${docU}.csv
done


Last edited by A-V; 02-19-2014 at 08:28 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. What is on Your Mind?

Custom Fonts for Usernames, Buttons, Other Short Phrases

I'm thinking to replace many of the buttons like "Reply" or "Thank You" with custom, modern, space age'e looking fonts. When I was game-engine programming in Unity last year, I used fonts like "Terminator" and "Neuropol" and "Space Age" and "Jupiter". At the moment, I cannot get "Neuropol" to... (2 Replies)
Discussion started by: Neo
2 Replies

2. Shell Programming and Scripting

Partial content greping into a 3rd file

Hi, I do have couple of files in folder. The names of each of the files have a pattern. B_A17_A17_1T.txt B_A17_A17_2T.txt B_A17_A17_3T.txt B_A17_A17_7T.txt ..... ..... B_A17_A17_45T.txt Each of the above files have the same pattern of data with 4 columns and have an header for... (10 Replies)
Discussion started by: Kanja
10 Replies

3. Shell Programming and Scripting

Greping values from a text file

Hi All, I have 100's of files in the following format. I need to grep or parse out some values from each of the files {  “tree”: “((A:0.2{0},B:0.09{1}):0.7{2},C:0.5{3}){​4};”,  “placements”:  , ], “n”: },   {“p”: ], “n”: } ],  “metadata”:  {“invocation”:   “pplacer -c... (1 Reply)
Discussion started by: Lucky Ali
1 Replies

4. Shell Programming and Scripting

Need Help with greping two line from a file Pls help ASAP

Hi all - I''m in a little bit of jam - If you can please help I have a file that has the following content ( please see below) I need to read the file and then get this result in this format ------------- To put out in this format name: sophis Total: 22328 name: tca ... (2 Replies)
Discussion started by: mnassiri
2 Replies

5. Shell Programming and Scripting

greping $2 into a list

Hi When I run this command: lsuser -a auditclasses ALL I got: user1 auditclasses=general,objects,cron,files,rbac,audit,lvm,aixpert user2 auditclasses=general,objects,cron,files,rbac,audit,lvm,aixpert user3 auditclasses=general,objects,cron,files,rbac,audit,lvm,aixpert user4... (7 Replies)
Discussion started by: iga3725
7 Replies

6. Shell Programming and Scripting

Matching a string (zip code) from a list in a separate file

I have a list of postal addresses and I need to pull the records that match a list of zip codes in a separate file. The postal addresses are fixed width. The zip code is located in character position 149-157. Something better than: cat postalfile.txt | grep -f zipcodes.txt would be great. $... (8 Replies)
Discussion started by: sitney
8 Replies

7. AIX

Filesystem /phrases 100% full because of some phrases*.icp files

This morning I see on one of our monitors that we have a server with the filesystem /phrases 100% full. Looking at it, I see 4 phrases*.icp files which are big and were created around midnight. I asked the previous operator what was running at that time (batch processing transaction files) and from... (0 Replies)
Discussion started by: Browser_ice
0 Replies

8. Shell Programming and Scripting

Greping columns data from file.

Hi i am using shell script which perform oracle database query and after that output is redirect to some temporary file. the output of this file looks like SQL*Plus: Release 10.2.0.2.0 - Production on Tue Aug 5 16:08:06 2008 Copyright (c) 1982, 2005, Oracle. All Rights Reserved. ... (6 Replies)
Discussion started by: esungoe
6 Replies

9. Shell Programming and Scripting

problem in greping the string from file using awk

I am using awk command for greping an value from the file the file contains .. file ---------------------------- content----------- -------- String main = "81507066666"; ------------------------------ i am greping the above value using awk command NumberToReplace=`cat "file" | grep... (1 Reply)
Discussion started by: vastare
1 Replies

10. Shell Programming and Scripting

greping date in a file

i have a script that checks inside the file and find the start date and end date with time........... #!/bin/ksh cd /ednadtu3/u01/pipe/logs TZ=`date +%Z`+24 ;b=`date +%Y-%m-%d` echo $b for i in DBMaint.log do echo "Start Time:" >> /ednadtu3/u01/pipe/naveed/Report.txt cat $i | grep... (3 Replies)
Discussion started by: ali560045
3 Replies
Login or Register to Ask a Question