Sponsored Content
Full Discussion: Comparing lines of data
Top Forums UNIX for Dummies Questions & Answers Comparing lines of data Post 302739067 by Don Cragun on Monday 3rd of December 2012 12:18:33 PM
Old 12-03-2012
Quote:
Originally Posted by markymarkg123
Total UNIX Rookie, but I'm learning. I have columns of integer data separated by spaces, and I'm using a Mac terminal.

What I want to do:
1. Compare "line 1 column 2" (x) to "line 2 column 2" (y); is y-x>=100?
2. If yes, display difference and y's line number
3. If no, increment x and y by one and repeat

How I am going about it:
Code:
sed -n '1,2 p' datafile | cut -d' ' -f1 #gives me the two fields of interest

Where do I go from here?
Your step 3 makes no sense to me. If y-x is not >= 100, then (y+1)-(x+1) can't be >= 100 either. This will just create an very large loop until one of the values overflows. So, until you can explain why this should be done, I'm going to ignore this requirement.

The proposal elixir_sinari makes the assumption that you are only comparing x values on odd numbered lines against y values on even numbered lines. Seeing your sample data and comments in message #6 in this thread, it looks like you want to compare the value in the 2nd column of your input file for every line except the 1st.

This slight modification to elixir_sinari's proposal:
Code:
awk '(NR>1) && (d=$2-x)>=100{print d,NR}{x=$2}' file

produces the output:
Code:
1741.1 5
1000 6
1741.1 14
1000 15
1741.1 23
1000 24

with your sample data. Is this what you wanted?
This User Gave Thanks to Don Cragun For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Comparing data list...

I have a list of files that I want to compare to another list of files, how do I do that? The first list will be my known list and hard coded, for example: mylist="janfile.tar jarfile.jar jan.rpt.Z" etc. The second list will be found by doing an 'ls' piped to a file: ls > filelist.dat ... (4 Replies)
Discussion started by: giannicello
4 Replies

2. Shell Programming and Scripting

comparing lines from 2 files

Hi Friends, I have 2 files A and B . I want to compare the 3rd line of file A and B . (I dont want to compare the 2 files, using diff or cmp). I just want to know whether 3rd line of A matches the 3 rd line of B. Can anybody share their knowledge on the same? Thanks , Vijaya (12 Replies)
Discussion started by: vijaya2006
12 Replies

3. Shell Programming and Scripting

Comparing data inside file

Hi Everyone, I will try to explain my question please forgive my english here. I am looking for shell script or command that can compare data in the files. I have 50 files in one directory test1 test2 test3 ....so on. I want to compare data in each files with each other and output each... (4 Replies)
Discussion started by: email-lalit
4 Replies

4. Shell Programming and Scripting

comparing lines in file

i have 2 files and i want to compare i currently cat the files and awk print $1, $2 and doing if file1=file2 then fail, else exit 0 what i want to do is compare values, with column 1 being a reference i want to compare line by line and then still be able to do if then statement to see if worked... (1 Reply)
Discussion started by: sigh2010
1 Replies

5. Shell Programming and Scripting

Comparing lines of two different files

Hello, Please help me with this problem if you have a solution. I have two files: <file1> : In each line, first word is an Id and then other words that belong to this Id piMN-1 abc pqr xyz py12 niLM y12 FY4 pqs fiRLym F12 kite red <file2> : same as file1, but can have extra lds... (3 Replies)
Discussion started by: mira
3 Replies

6. Shell Programming and Scripting

Extracting specific lines of data from a file and related lines of data based on a grep value range?

Hi, I have one file, say file 1, that has data like below where 19900107 is the date, 19900107 12 144 129 0.7380047 19900108 12 168 129 0.3149017 19900109 12 192 129 3.2766666E-02 ... (3 Replies)
Discussion started by: Wynner
3 Replies

7. Shell Programming and Scripting

Comparing the data in a 2 files

Hi Friends, I have a file 1 CREATE MULTISET TABLE TEYT_Q9_T.TEST ,NO FALLBACK , NO BEFORE JOURNAL, NO AFTER JOURNAL, CHECKSUM = DEFAULT, DEFAULT MERGEBLOCKRATIO ( XYZ DECIMAL(10,0), ABC VARCHAR(5) CHARACTER SET LATIN NOT CASESPECIFIC, PQR... (3 Replies)
Discussion started by: i150371485
3 Replies

8. Shell Programming and Scripting

Comparing to 3 data

# cat list.txt server1 server2 server3 server4 # data to be compared of. #dns address 1.1.1.1 2.2.2.2 3.3.3.3 #for i in `cat list.txt` do grep dns $ i done (1 Reply)
Discussion started by: invinzin21
1 Replies

9. UNIX for Dummies Questions & Answers

Comparing lines within a word list

Hello all- New to this forum, and relatively new to using grep at the Terminal command line to work with regular expressions. I've got a background in math and some programming experience, so it's not been too difficult to learn the basics of searching through my word lists for particular types of... (13 Replies)
Discussion started by: dtalvacchio
13 Replies

10. Shell Programming and Scripting

Comparing multiple lines in same file

Hello, I would like to write a /bin/ksh script to manipulate a file and compare its contexts. Comparing lines 1 & 2, 3 & 4, 5 & 6, and so forth until the end of the file. This is what I would like the script to compare (using line 1 & 2 as an example): 1. Verify if the last column in line 1 is... (10 Replies)
Discussion started by: seekryts15
10 Replies
CAPISUITE(8)															      CAPISUITE(8)

NAME
capisuite - Python-scriptable ISDN telecommunication suite DESCRIPTION
CapiSuite is a Python-scriptable ISDN telecommunication suite. It uses the new CAPI interface for accessing your ISDN-hardware - so you'll need a card for which a CAPI compatible driver is available. Currently these are all cards manufactured by AVM and some Eicon cards. This man page only gives a short introduction, for the real documentation please see the HTML or PDF manual distributed with CapiSuite. CapiSuite tries to give the user the ability to code his own ISDN applications without having to fiddle around with all the dirty program- ming details like callback functions, data buffers, protocol settings and so on. I took a scripting language which is (in my opinion) very easy to understand, to use and to learn - especially for beginners: Python. I extended it with some functions providing the basic ISDN "building blocks" for the users application. Behind these functions the heart of CapiSuite implements all the dirty details a user isn't interested in. My goal was to make script-coding as simple as possible but to also give you the flexibility to realize what you want. To give you an impression, coding a simple answering machine is as easy as:.IP .nf def callIncoming (call, service, call_from, call_to): connect_voice (call, 10) # answer call after 10 secs audio_send (call, "announcemnt.la") # play announcement audio_send (call, "beep.la") # play beep audio_receive (call, "call.la", 10) # record call .fi Of course some details are missing like creating a unique filename or storing the additional information (called and calling party numbers, time, ...) - but I assume you got my idea. And - don't be afraid - if you just want to have a normal answering machine or send and receive some fax documents, you can use the default scripts distributed with CapiSuite. They give you already some nice features - e.g. the answering machine is multi-user ready, supports automatic fax detection and remote inquiry functions. You'll only need to tell CapiSuite some details like your own number, record an own announcement and that's it. So CapiSuite is already equipped for your daily telecommunication needs - but if you don't like to do the things the way I do - just change it or completely do it on your own. And if you write nice scripts or have changes to my default scripts, I would love to get and perhaps make them available for all users if you don't mind. SEE ALSO
capisuite.conf(5), fax.conf(5), answering_machine.conf(5), capisuitefax(1) AUTHOR
Gernot Hillier <gernot@hillier.de>. CAPISUITE(8)
All times are GMT -4. The time now is 06:18 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy