Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Count occurrence of string (based on type) in a column using awk Post 302937074 by xbin on Tuesday 3rd of March 2015 07:30:10 AM
Old 03-03-2015
As a "one liner" this would look like scrambled eggs.
Code:
awk '/AA|BB|CC/ {fcount++}
     /XY|RS|PQ/ {scount++}
     END { printf("%s\n%s\n",
           "Type1 = " fcount, "Type2 = " scount)
         }
' FILE

Of course, feel free to scramble. :-)
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

remove characters from string based on occurrence of a string

Hello Folks.. I need your help .. here the example of my problem..i know its easy..i don't all the commands in unix to do this especiallly sed...here my string.. dwc2_dfg_ajja_dfhhj_vw_dec2_dfgh_dwq desired output is.. dwc2_dfg_ajja_dfhhj it's a simple task with tail... (5 Replies)
Discussion started by: victor369
5 Replies

2. Shell Programming and Scripting

Count no of occurrence of the strings based on column value

Can anyone help me to count number of occurrence of the strings based on column value. Say i have 300 files with 1000 record length from which i need to count the number of occurrence string which is existing from 213 to 219. Some may be unique and some may be repeated. (8 Replies)
Discussion started by: zooby
8 Replies

3. Emergency UNIX and Linux Support

awk cut column based on string

Using awk I required to cut out column contain word "-Tag" regardles of any order of contents and case INsensitive -Tag:messages -P:/var/log/messages -P:/var/log/maillog -K:Error -K:Warning -K:critical Please Guide ...... --Shirish Shukla ---------- Post updated at 05:58 AM... (15 Replies)
Discussion started by: Shirishlnx
15 Replies

4. Shell Programming and Scripting

Count number of occurrence of a string in file

if there's a file containing: money king money queen money cat money also money king all those strings are on one line in the file. how can i find out how many times "money king" shows up in the line? egrep -c "money king" wont work. (7 Replies)
Discussion started by: SkySmart
7 Replies

5. Shell Programming and Scripting

Count occurrence of string in a column using awk

Hi, I want to count the occurrences of strings in a column and display as in example below: Input: get1 345 789 098 get2 567 982 090 fet4 777 610 632 get1 800 544 230 get1 600 788 451 get2 892 321 243 get1 673 111 235 fet3 789 220 278 fet4 768 222 341 output: 4 get1 345 789... (7 Replies)
Discussion started by: aydj
7 Replies

6. UNIX for Dummies Questions & Answers

[Solved] Awk: count occurrence of each character for every field

Hi, let's say an input looks like: A|C|C|D A|C|I|E A|B|I|C A|T|I|B as the title of the thread explains, I am trying to get something like: 1|A=4 2|C=2|B=1|T=1 3|I=3|C=1 4|D=1|E=1|C=1|B=1 i.e. a count of every character in each field (first column of output) independently, sorted... (4 Replies)
Discussion started by: beca123456
4 Replies

7. Shell Programming and Scripting

Insert Columns before the last Column based on the Count of Delimiters

Hi, I have a requirement where in I need to insert delimiters before the last column of the total delimiters is less than a specified number. Say if the delimiters is less than 139, I need to insert 2 columns ( with blanks) before the last field awk -F 'Ç' '{ if (NF-1 < 139)} END { "Insert 2... (5 Replies)
Discussion started by: arunkesi
5 Replies

8. Programming

awk to count occurrence of strings and loop for multiple columns

Hi all, If i would like to process a file input as below: col1 col2 col3 ...col100 1 A C E A ... 3 D E G A 5 T T A A 6 D C A G how can i perform a for loop to count the occurences of letters in each column? (just like uniq -c ) in every column. on top of that, i would also like... (8 Replies)
Discussion started by: iling14
8 Replies

9. Shell Programming and Scripting

Count of occurrence in particular column of the file.

Hi All, let's say an input looks like: C1,C2,C3,C4,C5,C6,C7,C8,C9,C10,C11 ---------------------------------- 1|0123452|C501|Z|Z|Z|E|E|E|E|E|E|E 1|0156123|C501|X|X|X|E|E|E|E|E|E|E 1|0178903|C501|Z|Z|Z|E|E|E|E|E|E|E 1|0127896|C501|Z|Z|Z|E|E|E|E|E|E|E 1|0981678|C501|X|X|X|E|E|E|E|E|E|E ... (6 Replies)
Discussion started by: suresh_target
6 Replies

10. Shell Programming and Scripting

Count occurrence of column one unique value having unique second column value

Hello Team, I need your help on the following: My input file a.txt is as below: 3330690|373846|108471 3330690|373846|108471 0640829|459725|100001 0640829|459725|100001 3330690|373847|108471 Here row 1 and row 2 of column 1 are identical but corresponding column 2 value are... (4 Replies)
Discussion started by: angshuman
4 Replies
libst_intro(3)						     Library Functions Manual						    libst_intro(3)

NAME
libst_intro, libst - Symbol table and object file access library SYNOPSIS
#include <st.h> DESCRIPTION
libst.a contains a collection of functions for accessing object file data and symbol table information. These functions effectively insu- late the calling program from knowledge of the overall structure of the object file. An object can be a file with a .o suffix, a nonshared or call-shared executable, or a shared library. The libst function can also be used to access objects in archive libraries. The libst.a functions are particularly useful for developing tools that must access file, procedure, symbol, or line number information. They can assist in the development of Atom-based tools for application performance tuning and debugging. (See atom(1) for more information on the Atom tool kit.) The header file /usr/include/st.h contains all definitions and function prototypes needed for utilizing libst.a functions. Some applica- tions may also need to include the <cmplrs/demangle_string.h> header file to control name-demangling operations for C++ objects. By default, name demangling is enabled by libst when an object is opened. Functions allow you to manage both a single object and lists of objects. Object lists are useful when a call-shared object and one or more shared libraries that it uses must be available simultaneously. Interface routines provide access to object file header information and the symbol table. The symbol table contains information on source files, procedures, symbols, symbol type/class/size information, and lines. Address look-up routines are provided for text, data, and bss addresses. Access is provided where applicable to obtain information at the list, object, and source file level. For example, you can obtain the number of procedures in an entire object, or the number of procedures in a particular file. Functions return handles for objects, files, procedures, and symbols. libst functions are reentrant but not threadsafe. The calling program must synchronize thread access to objects or lists of objects. You should serialize access to an object list whenever an object is appended or when the object list is closed. At the object level, you should serialize calls to st_proc_sort, for instance. If a thread changes name demangling for an object, then you should both set the name- demangling flag and perform the name translation before another thread makes a name-translation call, such as st_sym_name. Generally, most calls to libst are read requests and do not require synchronization. EXAMPLES
The following code example shows how to use libst routines to list the file and procedure names in an object file. The build command for this program is: cc -g test.c -o test -lst -lmld This command ensures that libst will use any newer C++ demangler that has been installed along with a C++ compiler. The program is linked as a call-shared program, so the demangler in libmld.a loads libdemangle.so dynamically using ldopen(3), and it runs the shared library's demangler if that one is newer. To link a non-shared program so that libst uses a newer (or older) demangler in libdemangle.a, use this build command: cc -non_shared test.c -o test -lst -all -qldemangle -none -lmld #include <st.h> main(int argc, char **argv) { st_status_t ret; st_obj_t *obj; st_file_t file; st_proc_t proc; unsigned int fcount; unsigned int pcount; char *fname; char *pname; st_bool_t stripped; st_addr_t paddr; int i, j; if(argc < 2) { printf("Usage: test object_name "); exit(1); } /* Open the object. For C++, name demangling is enabled * when an object is successfully opened. */ if((ret = st_obj_open(&obj, argv[1], ST_RDONLY))) { printf("open ret = %d ",ret); exit(1); } /* If the object is stripped, exit since no symbolic * information is available. */ st_is_obj_stripped(obj, &stripped); if(stripped) { printf("Object %s is stripped ", argv[1]); exit(0); } /* Get handle for first file in the object and the count * of files. */ st_obj_file_start(obj, &file); st_obj_file_count(obj, &fcount); /* Loop through the files in the object, printing the * procedures contained in each. File names and static * procedure names are unavailable for files that were not * compiled with -g. */ for(i = 0; i < fcount; i++) { st_is_file_locally_stripped(obj, file, &stripped); if(stripped) printf("File is locally stripped - name is unavailable: "); else { st_file_name(obj, file, &fname); printf("File %s: ", fname); } /* Get handle for first procedure for this file, and the * count of procedures in the file. */ st_file_proc_start(obj, file, &proc); st_file_proc_count(obj, file, &pcount); /* Loop through the procedures for the file, printing the * procedure name if available. Static procedure names are not * available, for example, if the file was not compiled with -g. */ for(j=0; j < pcount; j++) { st_file_t fi; char *fn; /* If name lookup fails, get the procedure address */ if((ret = st_proc_name(obj, proc, &pname))) st_proc_addr(obj, proc, &paddr); if(!ret) printf(" Procedure %s ", pname); else printf(" Procedure at 0x%p ",paddr); st_file_proc_next(obj, file, proc, &proc); } st_obj_file_next(obj, file, &file); } ret = st_obj_close(obj); if (ret) { printf("close ret = %d ",ret); exit(1); } exit (0); } RETURN VALUES
All functions indicate success by returning a value of 0 (zero). A positive return value is an errno value from a system call. A negative return value is a library error or informational code. The library codes are documented in st.h. Return parameters are set to 0 or -1 when an error occurs. Address parameters are set to 0, and file and procedure handles are set to -1. An exception to this occurs when a NULL pointer for the object or other return parameter is input. In these cases, the return parameters will be unchanged. A non-zero return status is the recommended method for detecting an error return from a libst function. FILES
Header file that contains all definitions and function prototypes for libst.a functions Header file that controls name-demangling opera- tions for C++ objects RELATED INFORMATION
Commands: atom(1) Functions: st_addr_to_file(3), st_cm_setup(3), st_file_lang(3), st_get_known_versions(3), st_lang_str(3), st_obj_calls(3), st_obj_file_start(3), st_obj_open(3), st_objlist_append(3), st_proc_addr(3), st_pt_setup(3), st_strerror(3), st_sym_value(3). delim off libst_intro(3)
All times are GMT -4. The time now is 04:52 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy