Sponsored Content
Full Discussion: How to use NA and FNR?
Top Forums Shell Programming and Scripting How to use NA and FNR? Post 302900978 by Scrutinizer on Friday 9th of May 2014 05:31:04 PM
Old 05-09-2014
This is a duplicate of this thread.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk: different between NR and FNR

As I know: FNR: The ordinal number of the current record in the current file. NR: The ordinal number of the current record from the start of input. I don't understand really differency between NR and FNR. Who can explain it for me? And give me an example. Thanks (1 Reply)
Discussion started by: anhtt
1 Replies

2. Shell Programming and Scripting

NR==FNR for getting Col4 value from 2nd file

Multiple versions of this are probably in this section, but could not find one just right for me. My code gives me a zero byte file. Problem: foo 553 403 448 492 451 403 456 560 527 534 529 550 500 447 404 (6 Replies)
Discussion started by: genehunter
6 Replies

3. UNIX for Dummies Questions & Answers

awk NR==FNR output control

Hi Guys, I have two files: f1: A B C D E F G H f2: A X Y Z f1 has 48000 lines, and f2 has 68. I have been matching f1 $3 to f2 $1, and getting f3: A A B C D E F G I would like f3 too look like this: A X Y Z A B C D E F G (2 Replies)
Discussion started by: heecha
2 Replies

4. Shell Programming and Scripting

NR=FNR

cat file1 1 a b c 2 d e f 3 a f r cat file2 a c e output should be 1 3 means: if field 1 of file2 matches filed 2 of file1 then print field 1 of file1 I know that it can be done using awk NR=FNR. But not able to acheive it. Thanks in advance. (9 Replies)
Discussion started by: shaan4uster
9 Replies

5. Shell Programming and Scripting

Awk FNR==NR question

awk -F'' 'FNR==NR {a=$2; next} {$1=a} 1' $useralias ${entries} >> ${entries}_2 Hi, Is there anyway to alter this command so that if it does not find a match it will just leave the line alone instead of replacing what it doesn't find with a blank space? (4 Replies)
Discussion started by: Jazmania
4 Replies

6. Shell Programming and Scripting

NR==FNR confusions

This has been asked and answered hundreds of times, but I can't understand the syntax of awk's NR==FNR trick for merging files and printing the correct columns. Here's my File 1 1 rs8179466 224176 A ADD 1037 1.066 0.1421 0.8065 1.408 0.4468 ... (3 Replies)
Discussion started by: roofus
3 Replies

7. Shell Programming and Scripting

Tip: alternative for NR==FNR in awk

Example: $ cat file1 2 3$ cat file2 1 2 3 4 5 6The following awk script works like a charm, NR==FNR is true for file1, the remainder runs for file2: awk ' NR==FNR {A; next} ($1 in A) ' file1 file2 2 3Now have an empty file1: >file1and run the awk script again. The result is empty... (8 Replies)
Discussion started by: MadeInGermany
8 Replies

8. Shell Programming and Scripting

Help with Alternative for NR==FNR

Hi, I have an issue with the below script nawk 'NR==FNR{a=$4" "$5}NR>FNR{print NF?$0:a"\n";if(/^cn:/) x=$0}' FS="" in1.txt in2.txt > out1.txt It is taking too long to get a string from in1.text, search for the string in in2.txt and create a new file out1.txt. Is there any alternative way we... (1 Reply)
Discussion started by: Samingla
1 Replies

9. Shell Programming and Scripting

Explanation of FNR in this awk script

To merge mutiple *.tab files as: file1.tab rs1 A A rs2 A A rs3 C C rs4 C Cfile2.ind rs1 T T rs2 T T rs3 G G rs4 G Gand file3.tab rs1 B B rs2 B B rs3 L L rs4 L LOutput: file1.tab file2.tab file3.tab AA TT BB AA TT BB CC GG LL CC GG ... (4 Replies)
Discussion started by: yifangt
4 Replies

10. UNIX for Beginners Questions & Answers

Using NR==FNR Command

Dear All, I have below two files with me: file 1: A|B E|F C|D file 2: A|X|Y R|T|I C|V|N I want to compare 1st column of each file and than print both columns of file 1 and column 2 and 3 of file 2 Sample required output in regards to above files is below: A|B|X|Y C|D|V|N (5 Replies)
Discussion started by: Nebula
5 Replies
comm(1) 							   User Commands							   comm(1)

NAME
comm - select or reject lines common to two files SYNOPSIS
comm [-123] file1 file2 DESCRIPTION
The comm utility reads file1 and file2, which must be ordered in the current collating sequence, and produces three text columns as output: lines only in file1; lines only in file2; and lines in both files. If the input files were ordered according to the collating sequence of the current locale, the lines written will be in the collating sequence of the original lines. If not, the results are unspecified. OPTIONS
The following options are supported: -1 Suppresses the output column of lines unique to file1. -2 Suppresses the output column of lines unique to file2. -3 Suppresses the output column of lines duplicated in file1 and file2. OPERANDS
The following operands are supported: file1 A path name of the first file to be compared. If file1 is -, the standard input is used. file2 A path name of the second file to be compared. If file2 is -, the standard input is used. USAGE
See largefile(5) for the description of the behavior of comm when encountering files greater than or equal to 2 Gbyte ( 2^31 bytes). EXAMPLES
Example 1 Printing a list of utilities specified by files If file1, file2, and file3 each contain a sorted list of utilities, the command example% comm -23 file1 file2 | comm -23 - file3 prints a list of utilities in file1 not specified by either of the other files. The entry: example% comm -12 file1 file2 | comm -12 - file3 prints a list of utilities specified by all three files. And the entry: example% comm -12 file2 file3 | comm -23 -file1 prints a list of utilities specified by both file2 and file3, but not specified in file1. ENVIRONMENT VARIABLES
See environ(5) for descriptions of the following environment variables that affect the execution of comm: LANG, LC_ALL, LC_COLLATE, LC_CTYPE, LC_MESSAGES, and NLSPATH. EXIT STATUS
The following exit values are returned: 0 All input files were successfully output as specified. >0 An error occurred. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWesu | +-----------------------------+-----------------------------+ |CSI |enabled | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ SEE ALSO
cmp(1), diff(1), sort(1), uniq(1), attributes(5), environ(5), largefile(5), standards(5) SunOS 5.11 3 Mar 2004 comm(1)
All times are GMT -4. The time now is 12:57 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy