Sponsored Content
Top Forums Shell Programming and Scripting Word Occurrences script using awk Post 302923183 by ksmarine1980 on Friday 31st of October 2014 12:24:19 AM
Old 10-31-2014
Thank you, Chubler! Any idea how I can print off the index value as well? Should I be using asorti instead of sort? I'd like my output to appear like the following example:

Index Word Count
1 the 247
2 a 215
3 to 201
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Count the number of occurrences of the word

I am a newbie in UNIX shell script and seeking help on this UNIX function. Please give me a hand. Thanks. I have a large file. Named as 'MyFile'. It was tab-delmited. I am told to write a shell function that counts the number of occurrences of the ord “mysring” in the file 'MyFile'. (1 Reply)
Discussion started by: duke0001
1 Replies

2. Shell Programming and Scripting

awk and gsub - how to replace only the first X occurrences

I have a text (text.txt) and I would like to replace only the first 2 occurrences of a word (but I might need to replace more): For example, if text is this: CAR sweet head hat red yellow CAR book brown tiger CAR cow CAR CAR milk I would like to replace the word "CAR" with word... (12 Replies)
Discussion started by: bingel
12 Replies

3. Homework & Coursework Questions

Du without directory and Grep for occurrences of a word

Assistance on work Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Files stored in ... (1 Reply)
Discussion started by: alindner
1 Replies

4. Shell Programming and Scripting

Count occurrences in awk

Hello, I have an output from GDB with many entries that looks like this 0x00007ffff7dece94 39 in dl-fini.c 0x00007ffff7dece97 39 in dl-fini.c 0x00007ffff7ab356c 50 in exit.c 0x00007ffff7aed9db in _IO_cleanup () at genops.c:1022 115 in dl-fini.c 0x00007ffff7decf7b in _dl_sort_fini (l=0x0,... (6 Replies)
Discussion started by: ikke008
6 Replies

5. Shell Programming and Scripting

Script to count word occurrences, but exclude some?

I am trying to count the occurrences of ALL words in a file. However, I want to exclude certain words: short words (i.e. <3 chars), and words contained in an blacklist file. There is also a desire to count words that are capitalized (e.g. proper names). I am not 100% sure where the line on... (5 Replies)
Discussion started by: Cronk
5 Replies

6. UNIX for Dummies Questions & Answers

BASH - Counting word occurrences in a Web Page

Hi all, I have to do a script bash (for university) that counts all word occurrences in a specific web page. anyone can help me?. Thanks :) (1 Reply)
Discussion started by: piacentero
1 Replies

7. UNIX for Dummies Questions & Answers

Awk: Counting occurrences between two files

Hi, I have two text files (1.txt and 2.txt). 2.txt contains two columns which are extracted from 1.txt using a simple if(condition) print. I want to: - count how many times the values contained in 2.txt appear in 1.txt -if they appear just one time, I have to delete the entire row in... (5 Replies)
Discussion started by: Pintug
5 Replies

8. Shell Programming and Scripting

awk Group By and count string occurrences

Hi Gurus, I'm scratching my head over and over and couldn't find the the right way to compose this AWK properly - PLEASE HELP :confused: Input: c,d,e,CLICK a,b,c,CLICK a,b,c,CONV c,d,e,CLICK a,b,c,CLICK a,b,c,CLICK a,b,c,CONV b,c,d,CLICK c,d,e,CLICK c,d,e,CLICK b,c,d,CONV... (6 Replies)
Discussion started by: Royi
6 Replies

9. UNIX for Advanced & Expert Users

Find 2 occurrences of a word and print file names

I was thinking something like this but it always gets rid of the file location. grep -roh base. | wc -l find . -type f -exec grep -o base {} \; | wc -l Would this be a job for awk? Would I need to store the file locations in an array? (3 Replies)
Discussion started by: cokedude
3 Replies

10. UNIX for Beginners Questions & Answers

awk or sed script to count number of occurrences and creating an average

Hi Friends , I am having one problem as stated file . Having an input CSV file as shown in the code U_TOP_LOGIC/U_HPB2/U_HBRIDGE2/i_core/i_paddr_reg_2_/Q,1,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,0,0... (4 Replies)
Discussion started by: kshitij
4 Replies
Dpkg::Index(3)							   libdpkg-perl 						    Dpkg::Index(3)

NAME
Dpkg::Index - generic index of control information DESCRIPTION
This object represent a set of Dpkg::Control objects. FUNCTIONS
my $index = Dpkg::Index->new(%opts) Creates a new empty index. See set_options() for more details. $index->set_options(%opts) The "type" option is checked first to define default values for other options. Here are the relevant options: "get_key_func" is a function returning a key for the item passed in parameters. The index can only contain one item with a given key. The function used depend on the type: for CTRL_INFO_PKG, CTRL_INDEX_SRC, CTRL_INDEX_PKG and CTRL_PKG_DEB it's simply the Package field; for CTRL_PKG_SRC and CTRL_INFO_SRC, it's the Source field; for CTRL_CHANGELOG it's the Source and the Version fields (concatenated with an intermediary "_"); for CTRL_FILE_CHANGES it's the Source, Version and Architecture fields (concatenated with "_"); for CTRL_FILE_VENDOR it's the Vendor field; for CTRL_FILE_STATUS it's the Package and Architecture fields (concatenated with "_"). Otherwise it's the Package field by default. $index->get_type() Returns the type of control information stored. See the type parameter set during new(). $index->add($item, [$key]) Add a new item in the index. If the $key parameter is omitted, the key will be generated with the get_key_func function (see set_options() for details). $index->load($file) Reads the file and creates all items parsed. Returns the number of items parsed. Handles compressed files transparently based on their extensions. $index->parse($fh, $desc) Reads the filehandle and creates all items parsed. Returns the number of items parsed. $index->save($file) Writes the content of the index in a file. Auto-compresses files based on their extensions. my $item = $index->new_item() Creates a new item. Mainly useful for derived objects that would want to override this method to return something else than a Dpkg::Control object. my $item = $index->get_by_key($key) Returns the item identified by $key or undef. my @keys = $index->get_keys(%criteria) Returns the keys of items that matches all the criteria. The key of the %criteria hash is a field name and the value is either a regexp that needs to match the field value, or a reference to a function that must return true and that receives the field value as single parameter, or a scalar that must be equal to the field value. my @items = $index->get(%criteria) Returns all the items that matches all the criteria. $index->remove_by_key($key) Remove the item identified by the given key. my @items = $index->remove(%criteria) Returns and removes all the items that matches all the criteria. $index->merge($other_index, %opts) Merge the entries of the other index. While merging, the keys of the merged index are used, they are not re-computed (unless you have set the options "keep_keys" to "0"). It's your responsibility to ensure that they have been computed with the same function. $index->sort(&sortfunc) Sort the index with the given sort function. If no function is given, an alphabetic sort is done based on the keys. The sort function receives the items themselves as parameters and not the keys. my $str = $index->output() "$index" Get a string representation of the index. The Dpkg::Control objects are output in the order which they have been read or added except if the order hae been changed with sort(). $index->output($fh) Print the string representation of the index to a filehandle. AUTHOR
Raphael Hertzog <hertzog@debian.org>. 1.16.15 2014-06-05 Dpkg::Index(3)
All times are GMT -4. The time now is 10:03 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy