Sponsored Content
Top Forums Shell Programming and Scripting Printing Number of Fields with the line number Post 302591918 by Android Control on Saturday 21st of January 2012 03:06:45 PM
Old 01-21-2012
Be careful with your expectations, as your results will actually be;

1 4
2 4
3 4

Even though the first two lines have nothing after the last "|" there will still be a count of 4 for each line - even for an empty field. You will need to manage that by either not adding the trailing "|" or checking for "relevant content" of each field. Something like, if a field = /^$/ then take 1 away from the value of NF.

If you have a consistent number of "|" then your NF will always be the same regardless of what is between them.
This User Gave Thanks to Android Control For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

printing a line number using awk

Hi Chaps, I'm trying to print the line number of a comma delimited file where the second field in the line is blank using AWK. Here is the code I have so far where am I going wrong. It is the last column in the file. nawk -v x==0 'BEGIN {FS=",";OFS=","} x++ if ($2 == " ") print $x' bob.tst ... (3 Replies)
Discussion started by: rjsha1
3 Replies

2. Shell Programming and Scripting

Adding a columnfrom a specifit line number to a specific line number

Hi, I have a huge file & I want to add a specific text in column. But I want to add this text from a specific line number to a specific line number & another text in to another range of line numbers. To be more specific: lets say my file has 1000 lines & 4 Columns. I want to add text "Hello"... (2 Replies)
Discussion started by: Ezy
2 Replies

3. Shell Programming and Scripting

printing line number

hi, i have a file, i need to search for a string , if the line contains i need to print that line number and line , please help thanks in advance Satya (5 Replies)
Discussion started by: Satyak
5 Replies

4. Shell Programming and Scripting

regarding about printing line number

Hello, I am testing some data to get line number at cursor position 9 and found some problem, the code is below.Assume we got 3 attribute. At second attribute, there are some data(eg.A41/A6) missing like at the fourth and six line 11006 A41 1888 11006 ... (7 Replies)
Discussion started by: davidkhan
7 Replies

5. UNIX for Dummies Questions & Answers

How to read contents of a file from a given line number upto line number again specified by user

Hello Everyone. I am trying to display contains of a file from a specific line to a specific line(let say, from line number 3 to line number 5). For this I got the shell script as shown below: if ; then if ; then tail +$1 $3 | head -n $2 else ... (5 Replies)
Discussion started by: grc
5 Replies

6. Shell Programming and Scripting

Printing the line number in bash script

Hi, I would like to know how do I print the line # in a script. My requirement is, I have a script which is about ~5000 lines long. If there are any errors happen I just exit. And I would like to add the line # of the script where the error happened. Thanks, (6 Replies)
Discussion started by: suryaemlinux
6 Replies

7. Shell Programming and Scripting

print the number of fields in each line

I am looking for equivalent of following awk command in perl # awk '{ print NF ":" $0 } ' junk1 8:VAH NIC_TYPE CONFIG SIZE_GB PILO KOM BHA_GRP DESCR 8:2 NIC6 cont 34 y n shal_orgrp /shal 8:4 NIC5 signa 52 n y shal_orgrp... (3 Replies)
Discussion started by: dynamax
3 Replies

8. Shell Programming and Scripting

Printing the line number of first column found

Hello, I have a question on how to find the line number of the first column that contains specific data. I know how to print all the line numbers of those columns, but haven't been able to figure out how to print only the first one that is found. For example, if my data has four columns: 115... (3 Replies)
Discussion started by: user553
3 Replies

9. Shell Programming and Scripting

awk to find number in a field then print the line and the number

Hi I want to use awk to match where field 3 contains a number within string - then print the line and just the number as a new field. The source file is pipe delimited and looks something like 1|net|ABC Letr1|1530||| 1|net|EXP_1040 ABC|1121||| 1|net|EXP_TG1224|1122||| 1|net|R_North|1123|||... (5 Replies)
Discussion started by: Mudshark
5 Replies

10. Shell Programming and Scripting

Print line if values in fields matches number and text

datafile: 2017-03-24 10:26:22.098566|5|'No Route for Sndr:RETEK RMS 00040 /ZZ Appl:PF Func:PD Txn:832 Group Cntr:None ISA CntlNr:None Ver:003050 '|'2'|'PFI'|'-'|'EAI_ED_DeleteAll'|'EAI_ED'|NULL|NULL|NULL|139050594|ActivityLog| 2017-03-27 02:50:02.028706|5|'No Route for... (7 Replies)
Discussion started by: SkySmart
7 Replies
NNTPSEND.CTL(5) 						File Formats Manual						   NNTPSEND.CTL(5)

NAME
nntpsend.ctl - list of sites to feed via nntpsend DESCRIPTION
The file <--prefix=PREFIX at configure>/nntpsend.ctl specifies the default list of sites to be fed by nntpsend(8). Comments begin with a number sign (``#'') and continue through the end of the line. Blank lines and comments are ignored. All other lines should consist of four fields separated by a colon. The first field is the name of the site as specified in the newsfeeds(5) file. The second field should be the hostname or IP address of the remote site. The third field, if non-empty, specifies the default head truncation size of site's batchfile. If this field is empty, no truncation is performed. If this field is of the form ``maxsize-truncsize'' then it is passed to shrinkfile as ``-m maxsize -s truncsize'', otherwise is of the form ``truncsize'' then it is passed as ``-s truncsize''. The fourth field specifies some default flags passed to innxmit(8). The flag ``-a'' is always given to innxmit and need not appear hear. If no ``-t timeout'' flag is given in this field and on the nntpsend command line, ``-t 180'' will be given to innxmit. HISTORY
Written by Landon Curt Noll <chongo@toad.com> for InterNetNews. This is revision 1.6, dated 1998/04/09. SEE ALSO
innxmit(8), newsfeeds(5), nntpsend(8), trunc(1). NNTPSEND.CTL(5)
All times are GMT -4. The time now is 11:34 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy