Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Finding difference in 1st field for rows of data Post 302767827 by RudiC on Thursday 7th of February 2013 02:19:18 PM
Old 02-07-2013
Not clear. The file seems to be comma AND multiple space delimited. AND, first four lines (and next four ... etc.) seem to contain identical values. It's easy to set a flag on a field changing, but to what avail? Where does $1 == "1" into play? I don't see a connection between your input sample and the desired output you post. Pls be more specific, post more detailed input / output samples.
And, btw, don't use $f in your awk script. That's a shell'ism; use f to reference the variable itself. In awk, $f would address the f'th field of the input line...
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Difference between two rows

Dears, I have a list as follows, 2 4 8 If I want to find the difference between two consecutive rows. Then I have to store the specific rows in two variables and then find the difference. Could someone tell how this can be done. Regards, (7 Replies)
Discussion started by: JimJim
7 Replies

2. Shell Programming and Scripting

Finding different rows

I have two files. They are prety much the same, except a few lines. I would like to get the differences between the two file, but only those differences and nothing more. "diff" and "sdiff" cannot seem to do it. "sdiff -s" gets close, but I still get "less than" or "greater than" signs in the... (2 Replies)
Discussion started by: dombi
2 Replies

3. Shell Programming and Scripting

Extract difference of two columns from different rows

Hello guys, Please help me to solve this problem. I have tried some awk commands but couldn't succeed. I have a tab delimited file where each record is separated by ------ and 4th column of each record is same. <INPUT FILE> ------ peon 53931587 53931821 ... (12 Replies)
Discussion started by: sam_2921
12 Replies

4. Shell Programming and Scripting

Difference between corresponding elements of successive rows

Hi, I have a file in the following format a1 b1 c1 d1 a2 b2 c2 d2 a3 b3 c3 d3 a4 b4 c4 d4 I need a script to find the difference between corresponding values of successive rows. So the output would have one less row than the input file and should look like: a2-a1 b2-b1 c2-c1 d2-d1... (4 Replies)
Discussion started by: sajal.bhatia
4 Replies

5. UNIX for Dummies Questions & Answers

Suggestion to convert data in rows to data in columns

Hello everyone! I have a huge dataset looking like this: nameX nameX 0 1 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 ............... nameY nameY 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 ..... nameB nameB 0 1 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 ..... (can be several thousands of codes) and I need... (8 Replies)
Discussion started by: kush
8 Replies

6. Shell Programming and Scripting

finding difference between two files

Hi, I have two files one with 12486 lines second one with 13116 As per the comparsion between two files the count have 630 difference I used diff command to find the difference between two files but it's not understandable could any one suggest any command to get 630 records in a new... (4 Replies)
Discussion started by: thelakbe
4 Replies

7. Shell Programming and Scripting

Summing up rows data regarding 1st column

Dear all, I have one file like LABEL A B C D E F G H I J K L M N G02100 64651.3 25630.7 8225.21 51238 267324 268005 234001 52410.9 18598.2 10611 10754.7 122535 267170 36631.4 G02100 12030.3 8260.15 8569.91 ... (4 Replies)
Discussion started by: AAWT
4 Replies

8. Shell Programming and Scripting

Need help in finding in date difference

Hi, My date is coming as STARTDATE=Sun Jul 15 00:34:23 2012 ENDDATE=Sun Jul 15 00:50:04 2012I want difference between these two dates,anyone's helps will be appriciated. Thanks Prasoon (3 Replies)
Discussion started by: prasson_ibm
3 Replies

9. Shell Programming and Scripting

Finding first difference between two files

Hi! I'd like to know if it is possible for a command to find the first difference between two large files, output that line from both file and stop, so no need to continue after that to save some computation time. I don't think looping through it will be efficient enough but that's the only... (6 Replies)
Discussion started by: Mojing
6 Replies

10. Shell Programming and Scripting

Finding difference in 2 different timestamps

Legends, I have a requirement to run the script exactly after one hour of completion of dependent script. Eg: Script B should run after one hour on the completion of Script A. I got the time stamps using following variables. these scripts runs in autosys > DATE=`date +%H:%M` >... (4 Replies)
Discussion started by: sdosanjh
4 Replies
join(1) 						      General Commands Manual							   join(1)

Name
       join - join files

Syntax
       join [ -a n] [ -e string] [ -j  n m] [ -o list] [ -t c]	file1 file2

Description
       The  command  compares a field in file1 to a field in file2.  If the two fields match, the command combines the line in file1 that contains
       the field with the line in file2 that contains the field.  The command writes its output to standard output.  If you specify a  hyphen  (-)
       in the file1 argument, compares standard input to the contents of file2.

       The command compares and combines the input files one line at a time. Each line in the input file contains one field that uses to determine
       if two lines should be joined.  This field is called the join field. By default, the command uses the first field in each line as the  join
       field.	The  command  compares	the join field in the first line of file1 to the join field in the first line of file2.  If the two fields
       match, the command joins the lines.  The command then compares the join fields in the second line of both files, and so on.

       In the input files, fields are separated by tab or space characters.  The command reads data from the first field until it encounters a tab
       or  space  character,  which  terminates the first field.   By default, the command ignores tab and space characters, so the next character
       that is not a tab or space begins the second field.  The second field is terminated by the tab or space that  follows  it,  and	the  third
       field begins with the next character that is not a tab or space.  The command reads fields in this way until it encounters a new line char-
       acter.  Any number of tabs or spaces can separate two fields, and any number of newline characters can separate two lines.

       Both file1 and file2 must be ordered in the collating sequence of the command on the fields that  the  two  files  are  to  be  joined.	By
       default, uses the first field in each line and collates the same as

       To  create  output,  the  command writes the join field, followed by the remaining fields in the line from file1, followed by the remaining
       fields in the line from file2 to the output file.  The following demonstrates how lines in the  output appear by default:
       join_field file1.field2 file1.field3 file1.field4 file2.field2 file2.field3

       By default, the command ignores lines that do not contain identical join fields.  The command writes no output for these lines.

       You can change how creates output using command options.  For example, you can cause the command to write output for lines that do not con-
       tain  identical	join  fields.	You  can  also	specify  a  list  using  the option.  In list, you supply a list of specifiers in the form
       file.field, where file is either 1 or 2 and field is the number of the field.  For example, 1.2 specifies the second  field  in	the  first
       file  and 2.4 specifies the fourth field in the second file. The following demonstrates how lines in the output appear if you use these two
       specifiers:
       file1.field2 field2.field4

   International Environment
       LC_COLLATE     If this environment variable is set and valid, uses the international language database named in the definition to determine
		      collation rules.

       LC_CTYPE       If this environment variable is set and valid, uses the international language database named in the definition to determine
		      character classification rules.

       LANG	      If this environment variable is set and valid uses the international language database named in the definition to  determine
		      collation  and character classification rules.  If LC_COLLATE or LC_CTYPE is defined their definition supercedes the defini-
		      tion of LANG.

Options
       -a[n]	   Write lines that contain unmatched join fields to the output file.  You can cause the command to  write  unmatched  lines  from
		   only  one  file  using  n.  If you specify 1 in n, writes unmatched lines only from file 1.	If you specify 2, writes unmatched
		   lines only from file 2.

		   If you omit the option, writes no output for unmatched lines.

       -e s	   Writes the string you specify in s to the output if you specify a nonexistent field in the list for the option.   For  example,
		   if lines in file 2 contain only three fields, and you specify 2.4 in list, writes s in place of the nonexistent field.

       -jn m	   Defines  field  m  in file n to be the join field. The command compares the field you specify in the option to the default join
		   field in the other file.  If you omit n, the command uses the mth field in both files.

       -1 m	   Use the m th field in the first file as the join field.  This option is equivalent to using m.

       -2 m	   Use the m field in the second file as the join field.  This option is equivalent to using m.

       -o list	   Output the joined data according to list.  The specifiers in list have the format file.field, where file is either 1 or  2  and
		   field is the number of the field.

       -tc	   Recognize the tab character c.  The presence of c in a line is significant, both for comparing join fields and creating output.

Restrictions
       If you specify the option, the command collates the same as with no options.

Examples
       Suppose that by issuing the following commands, you display the files shown in the example:
       % cat file_1
       apr     15
       aug     20
       dec     18
       feb     05
       % cat file_2
       apr     06
       aug     14
       date
       feb     15
       Both files are sorted in ascending order.

       If you issue the command without options, the output appears as follows:
       % join file_1 file_2
       apr 15 06
       aug 20 14
       feb 05 15
       The third line in each input file is not joined in the output because the join fields (date and dec) do not match.

       To  join  the  lines  in these files and format the output so that the second field from each file appears first and the first (join) field
       appears second, issue the following command:
       % join -o 1.2 1.1 2.2 2.1 file_1 file_2
       15 apr 06 apr
       20 aug 14 aug
       05 feb 15 feb
       To write lines that are unmatched to the output, issue the following command:
       % join -a file_1 file_2
       apr 15 06
       aug 20 14
       date
       dec 18
       feb 05 15

See Also
       awk(1), comm(1), sort(1), sort5(1), environ(5int)

																	   join(1)
All times are GMT -4. The time now is 03:21 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy