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, shell scripts, 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 to print missing and keep sequential ordering if not found cmccabe Shell Programming and Scripting 4 06-26-2017 04:14 PM
awk changing numbering in output file cmccabe Shell Programming and Scripting 2 08-18-2016 10:21 AM
Sequential numbering from 1 to ten Paul Walker Shell Programming and Scripting 6 02-25-2014 01:07 PM
Inserting new line if two sequential lines begin with the same string majormajormajor Shell Programming and Scripting 2 10-18-2013 10:31 AM
Add markup tag and sequential number after specific line LMHmedchem Shell Programming and Scripting 3 12-29-2012 05:30 PM
start line numbering with arbitrary number? paracetamol Shell Programming and Scripting 2 08-04-2011 08:29 AM
Tool to simulate non-sequential disk I/O (simulate db file sequential read) in C POSIX vrghost Programming 7 06-18-2011 07:08 AM
sequential to line sequential vakharia Mahesh Shell Programming and Scripting 5 02-04-2011 12:02 AM
Ghostscript output file numbering? RacerX UNIX for Dummies Questions & Answers 0 03-15-2010 06:23 PM
Append specific lines to a previous line based on sequential search criteria jesse Shell Programming and Scripting 3 08-21-2009 03:01 AM
AWK help to add up sequential values EAGL€ Shell Programming and Scripting 1 08-20-2009 02:09 PM
numbering each line in a text file pitagi Shell Programming and Scripting 5 03-12-2009 07:34 PM
sed or awk help - line numbering w/ different start value camwheel Shell Programming and Scripting 7 03-09-2009 05:26 AM
AWK Multi-Line Records Numbering Problem RacerX Shell Programming and Scripting 3 11-01-2007 11:44 AM
Reading special characters while converting sequential file to line sequential Rajeshsu Programming 2 07-10-2006 03:38 PM


All times are GMT -4. The time now is 09:15 PM.

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