Sponsored Content
Top Forums Shell Programming and Scripting Help with showing the difference in two lines of input Post 302167518 by Kweekwom on Thursday 14th of February 2008 04:34:05 PM
Old 02-14-2008
Quote:
Originally Posted by Klashxx
Supposing one line per file:
Code:
awk '
NR==FNR{sub(/\n/,"");a1[$0]=$0;next}
{sub(/\n/,"");a2[$0]=$0;if ( ! ( $0 in a1 ) ){print "In file 2 but not in 1:"$0}}
END {for ( i in a1 ) 
    if  ( ! ( i in a2 ) ) {print "In file 1 but not in 2:"i}
}' RS=' '  f1 f2

Thanks for looking into it Klashxx,

When I try your suggestion, and say I input these numbers:

255 256 280 290

I get this error:

awk: cmd. line:6: fatal: cannot open file `255' for reading (No such file or directory)

It always says it can't open the first number. I'm not good with awk, do you see where the problem is?

Thanks,

Kweekwom
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

word count showing wrong number of lines

Hi , I am using SUN OS Version 5.6. I have a file that contains records of length 270. when I do 'set nu' in vi editor, I get the count as 86. whereas when I do "wc -l" on the command prompt, it shows the count as only 85. this is very strange. why would the 'wc' show 1 record less. The job... (3 Replies)
Discussion started by: tselvanin
3 Replies

2. UNIX for Dummies Questions & Answers

counting lines and showing the output

First time poster - I have a huge file and i want to sort and compress it to something more readable Ex: FUTNCA01-SL1 DMT8a4 5 3 FUTNCA01-SL1 DMT8a4 5 9 FUTNCA01-SL1 DMT8a4 5 21 FUTNCA01-SL1 DMT8a4 5 22 FUTNCA01-SL1 DMT8a4 5 23 FUTNCA01-SL1 DMT8a4 5 24 FUTNCA01-SL1 DMT8a4 6 2... (13 Replies)
Discussion started by: jjoves
13 Replies

3. UNIX for Dummies Questions & Answers

awk help in calulating difference for last two lines

Hi all, I have a requirement for a script to find out the increase in memory. We have a log native_stderr.log where this will log. bash-2.05$ tail -40 native_stderr.log | grep ': freed' <GC(4140): freed 168190456 bytes, 66% free (180990488/271776256), in 253 ms> <GC(4141): freed... (4 Replies)
Discussion started by: senthilkumar_ak
4 Replies

4. Shell Programming and Scripting

difference between 1 st fields from consicutive lines

13608:End of Tests. 13811:End of Tests. 14014:End of Tests. 14217:End of Tests. 14420:End of Tests. 14623:End of Tests. 14826:End of Tests. 15029:End of Tests. 15232:End of Tests. 15435:End of Tests. 15638:End of Tests. i have file like above. i want difference betwwn first field of... (2 Replies)
Discussion started by: pankajd
2 Replies

5. Shell Programming and Scripting

Showing the first 4 lines of a file?

Is there a way to show the first 4 lines of a file without using head -4? In sed would it be sed '1,4d' ? What if I just wanted to display the 2nd line ONLY? How could this be done with AWK?...correctly with SED? (6 Replies)
Discussion started by: puttster
6 Replies

6. Shell Programming and Scripting

Help with script or command to differentiate difference between two input file?

I got two file write now. Input file 1: >data_1 DSFDFDSGFDSGSGEGTRTRERPOYIORPGKKGDSPKFSDKFPSDKFSPFS >data_34 WEEREREWREWOIQOPIEPDSKLFNDSFNSKNCASKJHDAFHAOUDFEOWWIOUFEWIUEWIRUEWIRUEWIORUEWOREWR >data_21 ASDASDQWEQWRQERFWPOTGIUWEIPOFIOFDSNFKSJDNFSKDHFKDSJHFKDSJHF >data_4... (14 Replies)
Discussion started by: perl_beginner
14 Replies

7. Shell Programming and Scripting

Perl : code on ping showing difference result

Hi all, I am using the below code to ping a code and print whehter the connection is successful or not. use Net::Ping; $p = Net::Ping->new(); my $host = "x.x.x.x"; # print "$host is alive.\n" if $p->ping($host); if ($p->ping($host,3)) { print... (0 Replies)
Discussion started by: scriptscript
0 Replies

8. Shell Programming and Scripting

What is difference between this two lines in script?

Hi Guys, What is difference between this two lines in script logger -p daemon.info -t postback Starting /opt/local/bin/backup-report and /opt/local/bin/backup-report is the backu script running twice here? Thanks, (2 Replies)
Discussion started by: manalisharmabe
2 Replies

9. Shell Programming and Scripting

Removing multiple lines from input file, if multiple lines match a pattern.

GM, I have an issue at work, which requires a simple solution. But, after multiple attempts, I have not been able to hit on the code needed. I am assuming that sed, awk or even perl could do what I need. I have an application that adds extra blank page feeds, for multiple reports, when... (7 Replies)
Discussion started by: jxfish2
7 Replies

10. Shell Programming and Scripting

Calculate time difference between two lines

i grepped the time stamp in a file as given below now i need to calculate time difference file data: 18:29:10 22:15:50 (5 Replies)
Discussion started by: vivekn
5 Replies
TAIL(1) 						    BSD General Commands Manual 						   TAIL(1)

NAME
tail -- display the last part of a file SYNOPSIS
tail [-F | -f | -r] [-q] [-b number | -c number | -n number] [file ...] DESCRIPTION
The tail utility displays the contents of file or, by default, its standard input, to the standard output. The display begins at a byte, line or 512-byte block location in the input. Numbers having a leading plus ('+') sign are relative to the beginning of the input, for example, ``-c +2'' starts the display at the second byte of the input. Numbers having a leading minus ('-') sign or no explicit sign are relative to the end of the input, for example, ``-n 2'' displays the last two lines of the input. The default start- ing location is ``-n 10'', or the last 10 lines of the input. The options are as follows: -b number The location is number 512-byte blocks. -c number The location is number bytes. -f The -f option causes tail to not stop when end of file is reached, but rather to wait for additional data to be appended to the input. The -f option is ignored if the standard input is a pipe, but not if it is a FIFO. -F The -F option implies the -f option, but tail will also check to see if the file being followed has been renamed or rotated. The file is closed and reopened when tail detects that the filename being read from has a new inode number. The -F option is ignored if reading from standard input rather than a file. -n number The location is number lines. -q Suppresses printing of headers when multiple files are being examined. -r The -r option causes the input to be displayed in reverse order, by line. Additionally, this option changes the meaning of the -b, -c and -n options. When the -r option is specified, these options specify the number of bytes, lines or 512-byte blocks to display, instead of the bytes, lines or blocks from the beginning or end of the input from which to begin the display. The default for the -r option is to display all of the input. If more than a single file is specified, each file is preceded by a header consisting of the string ``==> XXX <=='' where XXX is the name of the file unless -q flag is specified. EXIT STATUS
The tail utility exits 0 on success, and >0 if an error occurs. SEE ALSO
cat(1), head(1), sed(1) STANDARDS
The tail utility is expected to be a superset of the IEEE Std 1003.2-1992 (``POSIX.2'') specification. In particular, the -F, -b and -r options are extensions to that standard. The historic command line syntax of tail is supported by this implementation. The only difference between this implementation and historic versions of tail, once the command line syntax translation has been done, is that the -b, -c and -n options modify the -r option, i.e., ``-r -c 4'' displays the last 4 characters of the last line of the input, while the historic tail (using the historic syntax ``-4cr'') would ignore the -c option and display the last 4 lines of the input. HISTORY
A tail command appeared in PWB UNIX. BSD
June 29, 2006 BSD
All times are GMT -4. The time now is 06:26 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy