Sponsored Content
Top Forums Shell Programming and Scripting How to get the column number in awk? Post 302876661 by neutronscott on Tuesday 26th of November 2013 02:23:10 AM
Old 11-26-2013
NF is the number of fields in a line. You can walk across all of them to see if it equals SUB_ACC_NO like so:

Code:
$ awk -F\| '{ for (i=1;i<=NF;i++) if ($i == "SUB_ACC_NO") print i }' input
1

Since we only care about line 1 (where headers are), then use the condition NR==1 or you can exit early NR>1{exit}

Code:
awk -F\| 'NR>1{exit}1{ for (i=1;i<=NF;i++) if ($i == "SUB_ACC_NO") print i }' input

awk -F\| 'NR==1{ for (i=1;i<=NF;i++) if ($i == "SUB_ACC_NO") print i }' input

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to select a column from particular line number

The awk command awk -F: '{print $1}' test1 gives the first columns of all the lines in file ,is there some command to get a particular column from particular line . Any help is appreciated. thanks arif (4 Replies)
Discussion started by: mab_arif16
4 Replies

2. Shell Programming and Scripting

column number, awk, help

All, $ cat myf.txt A|xyz|1000|mm B|9000|xyz|ss C|BDE|2000|kk D|xyz|1000|nn I am searching "xyz" $ awk -F "|" ' {for(k=0;k<=NF;k++) if ( $k == "xyz" ) print "line="NR"(column="k")" }' myf.txt Output: line=1(column=2) line=2(column=3) line=4(column=2) (2 Replies)
Discussion started by: jkl_jkl
2 Replies

3. UNIX for Dummies Questions & Answers

Adding a column with the row number using awk

Is there anyway to use awk to add a first column to my data that automatically goes from 1 to n , where n is the numbers of my rows?:confused: (4 Replies)
Discussion started by: cosmologist
4 Replies

4. UNIX for Dummies Questions & Answers

how to count number of rows and sum of column using awk

Hi All, I have the following input which i want to process using AWK. Rows,NC,amount 1,1202,0.192387 2,1201,0.111111 3,1201,0.123456 i want the following output count of rows = 3 ,sum of amount = 0.426954 Many thanks (2 Replies)
Discussion started by: pistachio
2 Replies

5. UNIX for Dummies Questions & Answers

count number of distinct values in each column with awk

Hi ! input: A|B|C|D A|F|C|E A|B|I|C A|T|I|B As the title of the thread says, I would need to get: 1|3|2|4 I tried different variants of this command, but I don't manage to obtain what I need: gawk 'BEGIN{FS=OFS="|"}{for(i=1; i<=NF; i++) a++} END {for (b in a) print b}' input ... (2 Replies)
Discussion started by: beca123456
2 Replies

6. Shell Programming and Scripting

Awk, appending a number in the first column of a row with a condition

Hi everyone, I have a data file in which the data is stored in event blocks. What I would like to get is that the same file with every data row starting with the number of event block. So here is two event blocks from my file: <event> -2 -1 0 0 0 501 0.00000000000E+00 ... (2 Replies)
Discussion started by: hayreter
2 Replies

7. Shell Programming and Scripting

awk - Print column number that return value comes from

I have the following awk script that I am using to find the max value in the file and print results. awk 'BEGIN {MAX=-1E100} {for (x=2; x<=NF; x++) if ($x>MAX) {MAX = $x; C1 = $1}} END {print substr(C1,1,11), substr(C1,13,4), substr(C1,18,2), MAX}' ABC* Input (ABC*) ... (6 Replies)
Discussion started by: ncwxpanther
6 Replies

8. Shell Programming and Scripting

awk to print column number while ignoring alpha characters

I have the following script that will print column 4 ("25") when column 1 contains "123". However, I need to ignore the alpha characters that are contained in the input file. If I were to ignore the characters my output would be column 3. What is the best way to print my column of interest... (3 Replies)
Discussion started by: ncwxpanther
3 Replies

9. Shell Programming and Scripting

Count Repetitive Number in a column and renumbering using awk

Unable to get the desired output. Need only the rows which has repeated values in column 5. Input File <tab separated file> chr1 3773797 3773797 CEP10 1 chr1 3773797 3773797 CEP104 2 chr1 3689350 3689350 SMIM1 2 chr1 3773797 3773797 CEP4 3 chr1 3773797 3773797 EP104 ... (7 Replies)
Discussion started by: himanshu
7 Replies

10. Shell Programming and Scripting

awk split columns to row after N number of column

I want to split this with every 5 or 50 depend on how much data the file will have. And remove the comma on the end Source file will have 001,0002,0003,004,005,0006,0007,007A,007B,007C,007E,007F,008A,008C Need Output from every 5 tab and remove the comma from end of each row ... (4 Replies)
Discussion started by: ranjancom2000
4 Replies
ldns-walk(1)						      General Commands Manual						      ldns-walk(1)

NAME
ldns-walk - Retrieve the contents of a DNSSEC signed zone SYNOPSIS
ldns-walk [ OPTION ] ZONE DESCRIPTION
ldns-walk is used to retrieve the contents of a DNSSEC signed zone. It does this through NSEC-walking (following the chain of NSEC records) and 'guessing' the next non-existent owner name for each NSEC. Note that it might get stuck on some wildcard records when used through a caching forwarder. This problem can be circumvented by querying the authoritative nameserver directly (with the @ argument). Of course the nameserver that is used must be DNSSEC-aware. OPTIONS
-f Do a 'full' zone walk; by default, ldns-walk will only show the names, and types present at those names. If this option is given, all resource records will be printed. -s name Start the walk with this owner name. Useful when continuing the walk for a large zone. @ nameserver Send the queries to this nameserver. BUGS
The full zone walk function is not complete yet, it does not correctly print delegation records AUTHOR
Written by Jelte Jansen as an example for ldns usage. REPORTING BUGS
Report bugs to <ldns-team@nlnetlabs.nl>. COPYRIGHT
Copyright (C) 2005 NLnet Labs. This is free software. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PUR- POSE. 21 Nov 2005 ldns-walk(1)
All times are GMT -4. The time now is 06:24 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy