awk changing numbering in output file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk changing numbering in output file
# 1  
Old 08-17-2016
awk changing numbering in output file

The below awk is supposed filter $8 of example.txt using the each line in gene.txt. I think it is but why is it renumbering the 1,2,3 in $1 to 28,29,394? I have attached the data as it is large, example.txt is the file to be searched, gene.txt has the lines to match, and filtered.txt is the current output. The desured output is just that but with $1 or R_Index sequentially numbered. Thank you Smilie.

awk
Code:
awk 'NR==FNR{for (i=1;i<=NF;i++) a[$i];next} FNR==1 || ($8 in a)' gene.txt example.txt | awk '{split($2,a,"-"); print a[1] "\t" $0}' | cut -f2-> filtered.txt

# 2  
Old 08-17-2016
How about this:

Code:
awk 'NR==FNR{for (i=1;i<=NF;i++) a[$i];next} $8 in a {$1=++n; print} FNR==1' gene.txt example.txt > filtered.txt

These 3 Users Gave Thanks to Chubler_XL For This Post:
# 3  
Old 08-18-2016
Thank you very much Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

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... (2 Replies)
Discussion started by: cmccabe
2 Replies

2. Shell Programming and Scripting

Changing format of file with awk

Hi all, I have a file that looks like this: Closest words to: manifesto >>>> Closest words to: passport >>>> and I want to reformat this with awk with the following desired result: manifesto 0.99999999999999978, 'manifesto' 0.72008211381623111, 'communiqu\xe9'... (5 Replies)
Discussion started by: owwow14
5 Replies

3. Shell Programming and Scripting

Awk script to run a sql and print the output to an output file

Hi All, I have around 900 Select Sql's which I would like to run in an awk script and print the output of those sql's in an txt file. Can you anyone pls let me know how do I do it and execute the awk script? Thanks. (4 Replies)
Discussion started by: adept
4 Replies

4. Shell Programming and Scripting

Help changing date output with AWK

Hello all, I have an issue where I'm trying to change a date in a csv text file. The file contains lines that have several fields. For example "John", "Smith","some_address","some_city","555-555-5555","11/11/1972" "Joan","User","some_address","some_city","444-444-4444","12/02/1963" The date... (6 Replies)
Discussion started by: commobox
6 Replies

5. UNIX for Dummies Questions & Answers

Ghostscript output file numbering?

I am using ghostscript to convert a multi-page pdf file to individual jpg files. I am wondering if there is a way to get ghostscript to start numbering the output jpg files from zero? What i am trying to convey is that it starts naming my files from page_001.jpg, page_002.jpg, etc., and would like... (0 Replies)
Discussion started by: RacerX
0 Replies

6. Shell Programming and Scripting

Changing file names with AWK

Dear All, I have some thousands of files in a folder and i need to change those file names without opening the file (no need to change anything in the file content, need to change the file name only). The filenames are as follows: Myfile_name.1_parameter Myfile_name.2_parameter... (6 Replies)
Discussion started by: Fredrick
6 Replies

7. UNIX for Dummies Questions & Answers

send output of a file as input for changing date

Hi, Please help me out on this one. I want to send the output of a file as input for changing the date using date command. Example, i have a file date.txt whose contents are 081014462009 I need to use the date in that file as input for date command. I tried cat date.txt | date ; but it... (2 Replies)
Discussion started by: foxtron
2 Replies

8. Shell Programming and Scripting

sed or awk help - line numbering w/ different start value

I'm pretty new to sed and awk, and I can't quite figure this one out. I've been trying with sed, as I'm more comfortable with it for the time being, but any tool that fits the bill will be fine. I have a few files, whose contents appear more or less like so: 1|True|12094856|12094856|Test|... (7 Replies)
Discussion started by: camwheel
7 Replies

9. Shell Programming and Scripting

AWK Multi-Line Records Numbering Problem

I have a set of files of multi-line records with the records separated by a blank line. I needed to add a record number to the front of each line followed by a colon and did the following: awk 'BEGIN {FS = "\n"; RS = ""}{for (i=1; i<=NF; i++)print NR,":",$i}' ~/Desktop/data98-1-25.txt >... (3 Replies)
Discussion started by: RacerX
3 Replies

10. UNIX for Dummies Questions & Answers

Changing persmissions for output file in UNIX box with SQR.

I am trying to change permissions on an output file from an sqr. The file is pushed out into a directory on the unix box. I am using the following code in the sqr to accomplish this. if $OUTPUT <> '' let $unix_call = 'chmod 664 '||$OUTPUT show $unix_call CALL SYSTEM Using... (1 Reply)
Discussion started by: evengetsteven
1 Replies
Login or Register to Ask a Question