Sponsored Content
Full Discussion: Data formation
Top Forums UNIX for Advanced & Expert Users Data formation Post 302752571 by Don Cragun on Monday 7th of January 2013 08:04:44 AM
Old 01-07-2013
Quote:
4. Are there always 3 fields in input lines, or do you want all fields combined no matter how many fields there are? Yes
The response Yes doesn't say which of the two specified behaviors you want implemented. The following should work either way but is more complex than is needed if there are always 3 input fields per line.

Code:
awk 'BEGIN {FS = OFS = "|"}
NR % 2 {o = $0          # This is the 1st line in a pair of lines.
        key = $1
        next    
}                       
{       if(key != $1) { # This is the 2nd line in a pair of lines.
            printf("1st field on line %d (%s) != 1st field on line %d (%s)\n",
                NR - 1, key, NR, $1) 
            exit 1  
        }       
        for(i = 2; i <= NF; i++) o = o OFS $i
        print o 
}' input_file

NOTE: On Solaris systems, use /usr/xpg4/bin/awk or nawk instead of awk.

Last edited by Don Cragun; 01-07-2013 at 12:02 PM.. Reason: Removed line of code that had been replaced earlier
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Howto capture data from rs232port andpull data into oracle database-9i automatically

Hi, i willbe very much grateful to u if u help me out.. if i simply connect pbx machine to printer by serial port RS232 then we find this view: But i want to capture this data into database automatically when the pbx is running.The table in database will contain similar to this view inthe... (1 Reply)
Discussion started by: boss
1 Replies

2. Shell Programming and Scripting

date command op formation

Dear All I am facing below mention problem plz suggest me solution. Op of date command: > date Tue Jan 1 12:17:52 IST 2008 Now i want Jan 1 12: or Jan 1 12 op in some another variable. I had tried awk but if give me problem when there is date comes in 2 digit i.e. greater that 9.... (1 Reply)
Discussion started by: jaydeep_sadaria
1 Replies

3. Shell Programming and Scripting

Extract data based on match against one column data from a long list data

My input file: data_5 Ali 422 2.00E-45 102/253 140/253 24 data_3 Abu 202 60.00E-45 12/23 140/23 28 data_1 Ahmad 256 7.00E-45 120/235 140/235 22 data_4 Aman 365 8.00E-45 15/65 140/65 20 data_10 Jones 869 9.00E-45 65/253 140/253 18... (12 Replies)
Discussion started by: patrick87
12 Replies

4. Shell Programming and Scripting

Formation of sql files

Dear Experts, I have a scenario where I have to form sql queries in a file using echo command. I have file1 which has more than 10 lac numbers. For each Number in file 1, I need to create 5 sql queries resulting in 50 lac queries totally. For doing this I use the below simple method, for i... (5 Replies)
Discussion started by: Naga06
5 Replies

5. Shell Programming and Scripting

Converting variable space width data into CSV data in bash

Hi All, I was wondering how I can convert each line in an input file where fields are separated by variable width spaces into a CSV file. Below is the scenario what I am looking for. My Input data in inputfile.txt 19 15657 15685 Sr2dReader 107.88 105.51... (4 Replies)
Discussion started by: vharsha
4 Replies

6. Shell Programming and Scripting

Perl string formation from array

HI I ma using perl programming my perl is like this $InputFile = $ENV{UDE_TMP} . "/" ."cre_fmr_gen.temp_data_file_gen.dat"; @duplicates = `cat $InputFile | cut -d "|" -f 1,1 | sort | uniq -c | awk '{ if(\$1>1) {print \$2;}}'`; my $cusiplist ; foreach $cusip (@duplicates) {... (1 Reply)
Discussion started by: ptappeta
1 Replies

7. Shell Programming and Scripting

Generate tabular data based on a column value from an existing data file

Hi, I have a data file with : 01/28/2012,1,1,98995 01/28/2012,1,2,7195 01/29/2012,1,1,98995 01/29/2012,1,2,7195 01/30/2012,1,1,98896 01/30/2012,1,2,7083 01/31/2012,1,1,98896 01/31/2012,1,2,7083 02/01/2012,1,1,98896 02/01/2012,1,2,7083 02/02/2012,1,1,98899 02/02/2012,1,2,7083 I... (1 Reply)
Discussion started by: himanish
1 Replies

8. Programming

Perl script to create football formation

I need help to create varieties of football formation. The available positions are: GK SW DR DC DL WBR DM WBL MR MC ML AMR AMC AML ST But the conditions are: a. the maximum number in 1 formation: GK is 1 SW is 1 (1 Reply)
Discussion started by: Tzeronone
1 Replies

9. Shell Programming and Scripting

Football formation

I'm trying to create a perl script that will automatically fit the player's name to the formation. For example, in my: DR.txt Arbeloa 200 Carvajal 190 Ramos 180 DC.txt Ramos 200 Pepe 190 Varane 180 DL.txt Marcelo 200 Coentrao 190 Arbeloa 180 formation.txt: DR DC DC DL DR (7 Replies)
Discussion started by: Tzeronone
7 Replies

10. Programming

Not a repeated question (Perl Script Create Football Formation)

https://www.unix.com/programming/252468-perl-script-create-football-formation.html https://www.unix.com/members/43551.html, it is not repeated question. please read it before u block my question. Unblock it for me. Thanks:mad: (0 Replies)
Discussion started by: Tzeronone
0 Replies
JOIN(1) 						      General Commands Manual							   JOIN(1)

NAME
join - relational database operator SYNOPSIS
join [-an] [-e s] [-o list] [-tc] file1 file2 DESCRIPTION
Join forms, on the standard output, a join of the two relations specified by the lines of file1 and file2. If file1 is `-', the standard input is used. File1 and file2 must be sorted in increasing ASCII collating sequence on the fields on which they are to be joined, normally the first in each line. There is one line in the output for each pair of lines in file1 and file2 that have identical join fields. The output line normally con- sists of the common field, then the rest of the line from file1, then the rest of the line from file2. Fields are normally separated by blank, tab or newline. In this case, multiple separators count as one, and leading separators are dis- carded. These options are recognized: -an In addition to the normal output, produce a line for each unpairable line in file n, where n is 1 or 2. -e s Replace empty output fields by string s. -o list Each output line comprises the fields specified in list, each element of which has the form n.m, where n is a file number and m is a field number. -tc Use character c as a separator (tab character). Every appearance of c in a line is significant. SEE ALSO
sort(1), comm(1), awk(1). BUGS
With default field separation, the collating sequence is that of sort -b; with -t, the sequence is that of a plain sort. The conventions of join, sort, comm, uniq, look and awk(1) are wildly incongruous. 7th Edition April 29, 1985 JOIN(1)
All times are GMT -4. The time now is 05:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy