Help in splitting Sub Fields and compare with other field


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help in splitting Sub Fields and compare with other field
Prev   Next
# 5  
Old 07-31-2014
Code:
awk     'NR==1                                          # print first line unaltered
                {n = split ($3, T, "$")                 # get $3's subfields by $ separator into T array
                 m = split ($4, F, "$")                 # same for $4
                 for (i=1;i<=n;i++) if (T[i]==1)        # check subfields for value 1
                         {print $1, $2, T[i], F[i]      # print line if yes
                          break}}                       # and stop the check
        ' FS=, OFS=, file4                              # make "," the field and output separator

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Is there a UNIX command that can compare fields of files with differing number of fields?

Hi, Below are the sample files. x.txt is from an Excel file that is a list of users from Windows and y.txt is a list of database account. $ head -500 x.txt y.txt ==> x.txt <== TEST01 APP_USER_PROFILE USER03 APP_USER_PROFILE TEST02 APP_USER_EXP_PROFILE TEST04 APP_USER_PROFILE USER01 ... (3 Replies)
Discussion started by: newbie_01
3 Replies

2. Shell Programming and Scripting

Inserting a field without disturbing field separator on other fields

Hi All, I have the input as below: cat input 032016002 2.891 97.109 16.605 27.172 24.017 32.207 0.233 0.021 39.810 0.077 0.026 19.644 13.882 0.131 11.646 0.102 11.449 76.265 23.735 16.991 83.009 8.840 91.160 0.020 99.980 52.102 47.898 44.004 55.996 39.963 18.625 0.121 1.126 40.189... (15 Replies)
Discussion started by: am24
15 Replies

3. Shell Programming and Scripting

awk - compare 1st 15 fields of record with 20 fields

I'm trying to compare 2 files for differences in a selct number of fields. When differnces are found it will write the whole record of the second file including appending '|C' out to a delta file. Each record will have 20 fields, but only want to do comparison of 1st 15 fields. The 1st field of... (7 Replies)
Discussion started by: sljnk
7 Replies

4. Shell Programming and Scripting

How to print 1st field and last 2 fields together and the rest of the fields after it using awk?

Hi experts, I need to print the first field first then last two fields should come next and then i need to print rest of the fields. Input : a1,abc,jsd,fhf,fkk,b1,b2 a2,acb,dfg,ghj,b3,c4 a3,djf,wdjg,fkg,dff,ggk,d4,d5 Expected output: a1,b1,b2,abc,jsd,fhf,fkk... (6 Replies)
Discussion started by: 100bees
6 Replies

5. Shell Programming and Scripting

Help with splitting fields

Hi. I want to put the first field to the end and the lines are of different number of fields. How should I do this with awk? Thanks. (3 Replies)
Discussion started by: dustinwang2003
3 Replies

6. Shell Programming and Scripting

Compare two files Field by field and output the result in another file

Hi Friends, Need Help. I have file1.txt as File1.txt |123|A|7267|Hyder|Cross|Sell|7801 |995|A|7051|2008|Lunar|New|Year|Promotion|7801 |996|A|7022|Q108|Targ|Prospect|&|SSCC|Savings|Promo|7801 |997|A|7182|Q1|Feb-Apr|08|Credit|ITA|PA|SBA|Campaign|7801 File2.txt... (7 Replies)
Discussion started by: i150371485
7 Replies

7. Shell Programming and Scripting

compare two fields and get a third field

Hello, I'm trying to get a value based on a comparison of two fields, this is: file1 687.45 687.18 687.322 687.405 686.865 file 2 685 6.43 686 6.43 687 6.42 688 6.42 (3 Replies)
Discussion started by: Gery
3 Replies

8. Shell Programming and Scripting

AWK: Pattern match between 2 files, then compare a field in file1 as > or < field in file2

First, thanks for the help in previous posts... couldn't have gotten where I am now without it! So here is what I have, I use AWK to match $1 and $2 as 1 string in file1 to $1 and $2 as 1 string in file2. Now I'm wondering if I can extend this AWK command to incorporate the following: If $1... (4 Replies)
Discussion started by: right_coaster
4 Replies

9. Shell Programming and Scripting

Compare Tab Separated Field with AWK to all and print lines of unique fields.

Hi. I have a tab separated file that has a couple nearly identical lines. When doing: sort file | uniq > file.new It passes through the nearly identical lines because, well, they still are unique. a) I want to look only at field x for uniqueness and if the content in field x is the... (1 Reply)
Discussion started by: rocket_dog
1 Replies

10. Shell Programming and Scripting

Sorting on two fields time field and number field

Hi, I have a file that has data in it that says 00:01:48.233 1212 00:01:56.233 345 00:09:01.221 5678 00:12:23.321 93444 The file has more line than this but i just wanted to put in a snippet to ask how I would get the highest number with time stamp into another file. So from the above... (2 Replies)
Discussion started by: pat4519
2 Replies
Login or Register to Ask a Question
SQL::Translator::Schema::Constraint(3pm)		User Contributed Perl Documentation		  SQL::Translator::Schema::Constraint(3pm)

NAME
SQL::Translator::Schema::Constraint - SQL::Translator constraint object SYNOPSIS
use SQL::Translator::Schema::Constraint; my $constraint = SQL::Translator::Schema::Constraint->new( name => 'foo', fields => [ id ], type => PRIMARY_KEY, ); DESCRIPTION
"SQL::Translator::Schema::Constraint" is the constraint object. METHODS
new Object constructor. my $schema = SQL::Translator::Schema::Constraint->new( table => $table, # table to which it belongs type => 'foreign_key', # type of table constraint name => 'fk_phone_id', # name of the constraint fields => 'phone_id', # field in the referring table reference_fields => 'phone_id', # referenced field reference_table => 'phone', # referenced table match_type => 'full', # how to match on_delete => 'cascade', # what to do on deletes on_update => '', # what to do on updates ); deferrable Get or set whether the constraint is deferrable. If not defined, then returns "1." The argument is evaluated by Perl for True or False, so the following are eqivalent: $deferrable = $field->deferrable(0); $deferrable = $field->deferrable(''); $deferrable = $field->deferrable('0'); expression Gets and set the expression used in a CHECK constraint. my $expression = $constraint->expression('...'); is_valid Determine whether the constraint is valid or not. my $ok = $constraint->is_valid; fields Gets and set the fields the constraint is on. Accepts a string, list or arrayref; returns an array or array reference. Will unique the field names and keep them in order by the first occurrence of a field name. The fields are returned as Field objects if they exist or as plain names if not. (If you just want the names and want to avoid the Field's overload magic use field_names). Returns undef or an empty list if the constraint has no fields set. $constraint->fields('id'); $constraint->fields('id', 'name'); $constraint->fields( 'id, name' ); $constraint->fields( [ 'id', 'name' ] ); $constraint->fields( qw[ id name ] ); my @fields = $constraint->fields; field_names Read-only method to return a list or array ref of the field names. Returns undef or an empty list if the constraint has no fields set. Useful if you want to avoid the overload magic of the Field objects returned by the fields method. my @names = $constraint->field_names; match_type Get or set the constraint's match_type. Only valid values are "full" "partial" and "simple" my $match_type = $constraint->match_type('FULL'); name Get or set the constraint's name. my $name = $constraint->name('foo'); options Gets or adds to the constraints's options (e.g., "INITIALLY IMMEDIATE"). Returns an array or array reference. $constraint->options('NORELY'); my @options = $constraint->options; on_delete Get or set the constraint's "on delete" action. my $action = $constraint->on_delete('cascade'); on_update Get or set the constraint's "on update" action. my $action = $constraint->on_update('no action'); reference_fields Gets and set the fields in the referred table. Accepts a string, list or arrayref; returns an array or array reference. $constraint->reference_fields('id'); $constraint->reference_fields('id', 'name'); $constraint->reference_fields( 'id, name' ); $constraint->reference_fields( [ 'id', 'name' ] ); $constraint->reference_fields( qw[ id name ] ); my @reference_fields = $constraint->reference_fields; reference_table Get or set the table referred to by the constraint. my $reference_table = $constraint->reference_table('foo'); table Get or set the constraint's table object. my $table = $field->table; type Get or set the constraint's type. my $type = $constraint->type( PRIMARY_KEY ); equals Determines if this constraint is the same as another my $isIdentical = $constraint1->equals( $constraint2 ); AUTHOR
Ken Youens-Clark <kclark@cpan.org>. perl v5.14.2 2012-01-18 SQL::Translator::Schema::Constraint(3pm)