👤
Home Man
Search
Today's Posts
Register

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

awk use sequential line numbering in output

Tags
awk, solved

👤 Login to reply

 
Thread Tools Search this Thread
# 1  
Old 11-16-2017
awk use sequential line numbering in output

The awk below produces an output with the original header and only the matching lines (which is good), but the output where the original line numbering in the match found on is used. I can not figure out how to sequentially number the output instead of using the original.

I did try to add {$1=++n; print} before the FNR==1 and though it executed the output was not correct. Thank you .

file1
Code:
LYST	NM_000081.3	chr1	235972867	235972867
MSH6	NM_000179.2	chr2	48027375	48027375

file2
Code:
R_Index	Chr	Start	End	Ref	Alt	Func.refGeneWithVer	Gene.refGeneWithVer
1362	chr1	235972867	235972867	T	C	exonic	LYST
5	chr1	985239	985239	C	T	splicing	AGRN
1701	chr2	48027375	48027375	T	C	exonic	MSH6


awk
Code:
awk -F'\t' 'NR==FNR{c[$1$3$4]++;next};c[$8$2$3] > 0; FNR==1' file1 file2

current output
Code:
R_Index	Chr	Start	End	Ref	Alt	Func.refGeneWithVer	Gene.refGeneWithVer
1362	chr1	235972867	235972867	T	C	exonic	LYST
1701	chr2	48027375	48027375	T	C	exonic	MSH6

desired output
Code:
R_Index	Chr	Start	End	Ref	Alt	Func.refGeneWithVer	Gene.refGeneWithVer
1	chr1	235972867	235972867	T	C	exonic	LYST
2	chr2	48027375	48027375	T	C	exonic	MSH6

# 2  
Old 11-16-2017
Code:
awk -F'\t' 'NR==FNR{c[$1$3$4]++;next}c[$8$2$3]>0{$1=++n;print}FNR==1' OFS='\t' file1 file2

The Following User Says Thank You to Yoda For This Useful Post:
cmccabe (11-17-2017)
# 3  
Old 11-17-2017
Thank you very much .
👤 Login to reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk changing numbering in output file cmccabe Shell Programming and Scripting 2 08-18-2016 09:21 AM
Sequential numbering from 1 to ten Paul Walker Shell Programming and Scripting 6 02-25-2014 12:07 PM
Inserting new line if two sequential lines begin with the same string majormajormajor Shell Programming and Scripting 2 10-18-2013 09:31 AM
start line numbering with arbitrary number? paracetamol Shell Programming and Scripting 2 08-04-2011 07:29 AM
sequential to line sequential vakharia Mahesh Shell Programming and Scripting 5 02-03-2011 11:02 PM
Ghostscript output file numbering? RacerX UNIX for Dummies Questions & Answers 0 03-15-2010 05:23 PM
numbering each line in a text file pitagi Shell Programming and Scripting 5 03-12-2009 06:34 PM
sed or awk help - line numbering w/ different start value camwheel Shell Programming and Scripting 7 03-09-2009 04:26 AM
AWK Multi-Line Records Numbering Problem RacerX Shell Programming and Scripting 3 11-01-2007 10:44 AM
Reading special characters while converting sequential file to line sequential Rajeshsu Programming 2 07-10-2006 02:38 PM


All times are GMT -4. The time now is 02:19 AM.



All times are GMT -4. The time now is 02:19 AM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password