Sponsored Content
Top Forums Shell Programming and Scripting Greping frequency for list of phrases is a separate file Post 302889227 by Yoda on Wednesday 19th of February 2014 12:43:20 PM
Old 02-19-2014
An awk approach:
Code:
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 "\t"
                for ( k in P )
                        printf "%s\t", k
                printf "\n"

                for ( j in F )
                {
                        printf "%s\t", j
                        for ( k in P )
                                printf "%s\t\t", (R[j FS k] ? R[j FS k] : 0)
                        printf "\n"
                }
        }
' phrases mark john

Input:
Code:
$ cat phrases
books
flowers
house pet
cooking skills

$ cat mark
I like reading books
I have five books
I love flowers
I am not allergic to flowers (list.txt)

$ cat john
I love house pets
I collect books

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

This User Gave Thanks to Yoda For This Post:
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Locale::Codes::LangExt(3pm)				 Perl Programmers Reference Guide			       Locale::Codes::LangExt(3pm)

NAME
Locale::Codes::LangExt - standard codes for language extension identification SYNOPSIS
use Locale::Codes::LangExt; $lext = code2langext('acm'); # $lext gets 'Mesopotamian Arabic' $code = langext2code('Mesopotamian Arabic'); # $code gets 'acm' @codes = all_langext_codes(); @names = all_langext_names(); DESCRIPTION
The "Locale::Codes::LangExt" module provides access to standard codes used for identifying language extensions, such as those as defined in the IANA language registry. Most of the routines take an optional additional argument which specifies the code set to use. If not specified, the default IANA language registry codes will be used. SUPPORTED CODE SETS
There are several different code sets you can use for identifying language extensions. A code set may be specified using either a name, or a constant that is automatically exported by this module. For example, the two are equivalent: $lext = code2langext('acm','alpha'); $lext = code2langext('acm',LOCALE_LANGEXT_ALPHA); The codesets currently supported are: alpha This is the set of three-letter (lowercase) codes from the IANA language registry, such as 'acm' for Mesopotamian Arabic. This is the default code set. ROUTINES
code2langext ( CODE [,CODESET] ) langext2code ( NAME [,CODESET] ) langext_code2code ( CODE ,CODESET ,CODESET2 ) all_langext_codes ( [CODESET] ) all_langext_names ( [CODESET] ) Locale::Codes::LangExt::rename_langext ( CODE ,NEW_NAME [,CODESET] ) Locale::Codes::LangExt::add_langext ( CODE ,NAME [,CODESET] ) Locale::Codes::LangExt::delete_langext ( CODE [,CODESET] ) Locale::Codes::LangExt::add_langext_alias ( NAME ,NEW_NAME ) Locale::Codes::LangExt::delete_langext_alias ( NAME ) Locale::Codes::LangExt::rename_langext_code ( CODE ,NEW_CODE [,CODESET] ) Locale::Codes::LangExt::add_langext_code_alias ( CODE ,NEW_CODE [,CODESET] ) Locale::Codes::LangExt::delete_langext_code_alias ( CODE [,CODESET] ) These routines are all documented in the Locale::Codes::API man page. SEE ALSO
Locale::Codes The Locale-Codes distribution. Locale::Codes::API The list of functions supported by this module. http://www.iana.org/assignments/language-subtag-registry The IANA language subtag registry. AUTHOR
See Locale::Codes for full author history. Currently maintained by Sullivan Beck (sbeck@cpan.org). COPYRIGHT
Copyright (c) 2011-2013 Sullivan Beck This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.18.2 2013-11-04 Locale::Codes::LangExt(3pm)
All times are GMT -4. The time now is 08:16 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy