Sponsored Content
Top Forums Shell Programming and Scripting How to loop my awk script across different columns? Post 302897128 by Scrutinizer on Friday 11th of April 2014 06:53:41 AM
Old 04-11-2014
Try something like:
Code:
awk '
  NR==1{
    n=split($0,Header)
    next
  }
  {
    for(i=2; i<=NF; i++) {
      if($i>0.5)  Total[i]++
      if($i<-0.5) Total[i]--
    }
  }
  END{
    for(i=2; i<=n; i++)
      print Header[i] ":" Total[i]
  }
' file

Output:
Code:
a1:1
a2:-1
a3:-1

This User Gave Thanks to Scrutinizer For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

AWK script to print all the columns excpet the one specified

I have several columns by the name A B C D E...... and I want to print all the column other than column C and D. Could you please help me with the awk script? Thanks!! (3 Replies)
Discussion started by: kn.naresh
3 Replies

2. Shell Programming and Scripting

for loop in awk script using ksh

Guys, I am new in awk , I face problem while i try to use for loop in awk, I am using ksh, i am trying to set a for loop which runs as man times as the records in a file , the for loop like for(a=1;a<=5;a++) is working in my awk script but the one i need is not working :wall: for example ... (8 Replies)
Discussion started by: djahmed
8 Replies

3. Shell Programming and Scripting

Awk script to replace null columns with blank

I have a file with contents "08011"||20080812 "23348"|20080827|20080924 "23387"|20080829|20080915 "23581"|20081003|20081028 "23748"|20081017|20090114 "24095"|20080919|20081013 "24105"|20070723|20070801 "24118"|20080806|20081013 "24165"|20080820|20080912 "24221"|20080908|20080929 i... (3 Replies)
Discussion started by: sonam273
3 Replies

4. Shell Programming and Scripting

Computing the ratio of similar columns in the two files using awk script

Thanks Bartus11 for your help in the following code to compare the two files "t1" and "t2". awk 'NR==FNR{a=1;next}$2 in a{print $2}' t1 t2 First can anyone explain that what is the purpose of assigning a =1? Second, the current script is printing out the matched columns between the... (4 Replies)
Discussion started by: coder83
4 Replies

5. Shell Programming and Scripting

awk based script to find the average of all the columns in a data file

Hi All, I need the modification for the below mentioned code (found in one more post https://www.unix.com/shell-programming-scripting/27161-script-generate-average-values.html) to find the average values for all the columns(but for a specific rows) and print the averages side by side. I have... (4 Replies)
Discussion started by: ks_reddy
4 Replies

6. Shell Programming and Scripting

awk script: loop through array

I have a large file where I want to extract the data by using awk script. I have made a small sample of the input data. I have in the awk script two condition . The first one is to collect the initial time and the second one to collect the end time. I stored the difference between (Time=end-start)... (8 Replies)
Discussion started by: ENG_MOHD
8 Replies

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

8. Linux

Problem with my loop and awk script

Sorry if this is a super simple issue, but am extremely new to this and am trying to teach myself as I go along. But can someone please help me out? I have a data file similar to this for many samples, for all chromosomes Sample Chr bp p roh Sample1 1 49598178 0 1... (14 Replies)
Discussion started by: vuvuzelo
14 Replies

9. Shell Programming and Scripting

awk script to remove last two columns

I am writing an awk script to remove the last two fields in a pipe delimited file. The script that I have currently deletes the last two fields but each field is being printed on its own line in the output. I can't seem to get the rows to print out on the same line as the input data. This is what I... (4 Replies)
Discussion started by: chamuco666
4 Replies

10. UNIX for Beginners Questions & Answers

Shell script, For loop output to excel as columns

Hi, I have a shell script which analyses the log folder for a specific string and throws me the output. I have used for loop since it does this in multiple servers. Now I want to save the output in a excel in the below format. Can someone please help? The output which I get Server1 : count... (14 Replies)
Discussion started by: srilaxman
14 Replies
Debian::Copyright::Stanza::Header(3pm)			User Contributed Perl Documentation		    Debian::Copyright::Stanza::Header(3pm)

NAME
Debian::Copyright::Stanza::Header - header stanza of Debian copyright file VERSION
This document describes Debian::Copyright::Stanza::Header version 0.1 . SYNOPSIS
my $copy = Debian::Copyright::Stanza::Header->new(\%data); print $copy; # auto-stringification DESCRIPTION
Debian::Copyright::Stanza::Header can be used for representation and manipulation of the header stanza of Debian copyright files in an object-oriented way. Converts itself to a textual representation in string context. FIELDS
The supported fields for header stanzas are listed below. Note that real copyright fields may contain dashes in their names. These are replaced with underscores. Format_Specification Name X_Comment Maintainer Source CONSTRUCTOR
new new( { field => value, ... } ) Creates a new Debian::Copyright::Stanza::Header object and optionally initialises it with the supplied data. SEE ALSO
Debian::Copyright::Stanza::Header inherits most of its functionality from Debian::Copyright::Stanza COPYRIGHT &; LICENSE Copyright (C) 2011 Nicholas Bamber nicholas@periapt.co.uk This module is substantially based upon Debian::Control::Stanza::Source. Copyright (C) 2009 Damyan Ivanov dmn@debian.org This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. perl v5.12.4 2011-08-27 Debian::Copyright::Stanza::Header(3pm)
All times are GMT -4. The time now is 06:03 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy