Sponsored Content
Top Forums Shell Programming and Scripting [Solved] Counting specific characters within each field Post 302718857 by elixir_sinari on Sunday 21st of October 2012 09:59:16 AM
Old 10-21-2012
With some assumptions (no field has a null/blank value):
Code:
awk '{
for(i=2;i<=NF;i++)
 if($i=="1") c_one[i]++
  else if($i=="2") c_two[i]++}
END{for(i=2;i<=NF;i++) printf("%d\t%d\n",c_one[i],c_two[i])}' file

This User Gave Thanks to elixir_sinari For This Post:
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

counting characters

Dears, I would like to count the number of "(" and ")" that occur in a file. (syntax checking script). I tried to use "grep -c" and this works fine as long as there is only one character (for which I do a search) on a line. Has anyone an idea how I can count the number of specific characters... (6 Replies)
Discussion started by: plelie2
6 Replies

2. HP-UX

extract field of characters after a specific pattern - using UNIX shell script

Hello, Below is my input file's content ( in HP-UX platform ): ABCD120672-B21 1 ABCD142257-002 1 ABCD142257-003 1 ABCD142257-006 1 From the above, I just want to get the field of 13 characters that comes after 'ABCD' i.e '120672-B21'... . Could... (2 Replies)
Discussion started by: jansat
2 Replies

3. Shell Programming and Scripting

counting characters

Hi All, I need some help in counting the number of letters in a big file with separations. Following is the file I have >AB_1 MLKKPIIIGVTGGSGGGKTSVSRAILDSFPNARIAMIQHDSYYKDQSHMSFEERVKTNYDHPLAFDTDFM IQQLKELLAGRPVDIPIYDYKKHTRSNTTFRQDPQDVIIVEGILVLEDERLRDLMDIKLFVDTDDDIRII... (6 Replies)
Discussion started by: Lucky Ali
6 Replies

4. Shell Programming and Scripting

Counting characters within a file

Ok say I wanted to count every Y in a data file. Then set Y as my delimiter so that I can separate my file by taking all the contents that occur BEFORE the first Y and store them in a variable so that I may use this content later on in my program. Then I could do the same thing with the next Y's... (5 Replies)
Discussion started by: puttster
5 Replies

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

6. Shell Programming and Scripting

Counting characters at each position

Hi All, here's a question from newbie I have a data like this, which set of small DNA sequences separated by new line GAATCCGGAAACAGCAACTTCAAANCA GTNATTCGGGCCAAACTGTCGAA TTNGGCAACTGTTAGAGCTCATGCGACA CCTGCTAAACGAGTTCGAGTTGAANGA TTNCGGAAGTGGTCGCTGGCACGG ACNTGCATGTACGGAGTGACGAAACCI... (6 Replies)
Discussion started by: amits22
6 Replies

7. Shell Programming and Scripting

[Solved] Error in script while counting processes

Hi all, Below is a script I'm writing and giving me error: #!/usr/bin/sh if ; then echo "Success!" else echo "Failure!" fi Normally if I do ps -ef|grep dw.sap|wc -l it gives me output of 18. So my script checks if it's greater than 17 it echoes success else failure ... (5 Replies)
Discussion started by: frum
5 Replies

8. UNIX for Dummies Questions & Answers

How to replace and remove few junk characters from a specific field?

I would like to remove all characters starting with "%" and ending with ")" in the 4th field - please help!! 1412007819.864 /device/services/heartbeatxx 204 0.547%!i(int=0) 0.434 0.112 1412007819.866 /device/services/heartbeatxx 204 0.547%!i(int=1) 0.423 0.123... (10 Replies)
Discussion started by: snemuk14
10 Replies

9. UNIX for Beginners Questions & Answers

Find records with specific characters in 2 nd field

Hi , I have a requirement to read a file ( 5 fields , ~ delimited) and find the records which contain anything other than Alphabets, Numbers , comma ,space and dot . ie a-z and A-Z and 0-9 and . and " " and , in 2nd field. Once I do that i would want the result to have field1|<flag> flag can... (2 Replies)
Discussion started by: ashwin3086
2 Replies
SVN_CHECKOUT(3) 							 1							   SVN_CHECKOUT(3)

svn_checkout - Checks out a working copy from the repository

SYNOPSIS
bool svn_checkout (string $repos, string $targetpath, [int $revision], [int $flags]) DESCRIPTION
Checks out a working copy from the repository at $repos to $targetpath at revision $revision. PARAMETERS
o $repos - String URL path to directory in repository to check out. o $targetpath - String local path to directory to check out in to Note Relative paths will be resolved as if the current working directory was the one that contains the PHP binary. To use the calling script's working directory, use realpath(3) or dirname(__FILE__). o $revision - Integer revision number of repository to check out. Default is HEAD, the most recent revision. o $flags - Any combination of SVN_NON_RECURSIVE and SVN_IGNORE_EXTERNALS. RETURN VALUES
Returns TRUE on success or FALSE on failure. NOTES
Warning This function is EXPERIMENTAL. The behaviour of this function, its name, and surrounding documentation may change without notice in a future release of PHP. This function should be used at your own risk. EXAMPLES
Example #1 Basic example This example demonstrates how to check out a directory from a repository to a directory named calc: <?php svn_checkout('http://www.example.com/svnroot/calc/trunk', dirname(__FILE__) . '/calc'); ?> The dirname(__FILE__) call is necessary in order to convert the calc relative path into an absolute one. If calc exists, you can also use realpath(3) to retrieve an absolute path. SEE ALSO
svn_add(3), svn_commit(3), svn_status(3), svn_update(3), SVN documentation on svn checkout. PHP Documentation Group SVN_CHECKOUT(3)
All times are GMT -4. The time now is 02:55 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy