Sponsored Content
Full Discussion: awk two fields in one array
Top Forums Shell Programming and Scripting awk two fields in one array Post 302594592 by sdf on Tuesday 31st of January 2012 05:41:49 PM
Old 01-31-2012
awk two fields in one array

I want to compare these files while putting $1 and $2 into an array and getting rid of the punctuation. What am i doing wrong?

File1.txt
HTML Code:
Apple # 223
Peach # 84;
Banana # 1605.
Banana # 1605;
Orange # 6;
Peach # 84
Peach # 84;
Apple # 229;
Banana # 1605.
Peach # 84
Apple, # 229;
Banana, # 1605.
Orange # 6b.
File2.txt
HTML Code:
Store 3: Apple # 223
Store 2: Apple # 229
Store 4: Apple # 229
Stroe 1: Apple # 200
Store 3: Banana # 1605
Store 1: Banana # 1605
Store 3: Banana # 1605
Store 5: Banana # 1605
Store 6: Banana # 1301
Store 1: Banana # 1301
Store 1: Peach # 84
Store 5: Peach #600
Store 3: Peach # 84
Store 2: Peach # 84
Store 4: Peach # 84
Store 1: Orange # 6
Store 3: Orange # 5
Store 2: Orange # 6b
Output.txt
HTML Code:
Store 3: Apple # 223
Store 2: Apple # 229
Store 4: Apple # 229
Store 3: Banana # 1605
Store 1: Banana # 1605
Store 3: Banana # 1605
Store 5: Banana # 1605
Store 1: Peach # 84
Store 3: Peach # 84
Store 2: Peach # 84
Store 4: Peach # 84
Store 1: Orange # 6
Store 2: Orange # 6b
Code:
awk -F'[:=#]' 'NR==FNR{a[$1 , $2];next} {if($2 in a[1] && $3 in a[2]) print $0}'


Last edited by sdf; 01-31-2012 at 06:54 PM.. Reason: added output.txt
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk reading many fields to array

I want to read $3,$4,$5,$6,$7 of fileA in array and when fileb $1 = fileA $4 the i want to print array and few fields from fileB. This should work but has some syntax error. nawk -F, 'FNR==NR{a=;next} a{print a}' fileB fileA Appreciate if someone can correct this. (2 Replies)
Discussion started by: pinnacle
2 Replies

2. Shell Programming and Scripting

awk sed cut? to rearrange random number of fields into 3 fields

I'm working on formatting some attendance data to meet a vendors requirements to upload to their system. With some help on the forums here, I have the data close. But they've since changed what they want. The vendor wants me to submit three fields to them. Field 1 is the studentid field,... (4 Replies)
Discussion started by: axo959
4 Replies

3. Shell Programming and Scripting

one solution if want fields in a file into each array

Hi Everyone, This is just my method to if want fields in a file into each array. # cat /tmp/3.txt 00:00:01 1 00:00:02 2 00:00:03 33 # cat text.pl #!/usr/bin/perl @field1 = `cat '/tmp/3.txt' | cut -f1 -d'\t'`; print $field1; # ./text.pl 00:00:01 # As we can... (4 Replies)
Discussion started by: jimmy_y
4 Replies

4. Shell Programming and Scripting

how to spilit a row into fields and store the field content to the array

consider this is a line A#B#C#D#E#F#G#H note the delimeter is # i want to cut or spilt in to fields using the delimeter # and to store in an array. like this array=A array=B array=C array=D array=E and the array content should be displayed. echo "${array}" echo "${array}"... (5 Replies)
Discussion started by: barani75
5 Replies

5. UNIX for Dummies Questions & Answers

Fill fields with awk from an array?

Hi experts, I have been trying for a while to accomplish the following task using awk, and I just don't seem find find a way. I am not particular about using awk, it just seemed like the logical choice at first. I have a file that contains 5 fields that are delimited by a space character.... (1 Reply)
Discussion started by: GermanicGalore
1 Replies

6. Shell Programming and Scripting

Join fields comparing 4 fields using awk

Hi All, I am looking for an awk script to do the following Join the fields together only if the first 4 fields are same. Can it be done with join function in awk?? a,b,c,d,8,,, a,b,c,d,,7,, a,b,c,d,,,9, a,b,p,e,8,,, a.b,p,e,,9,, a,b,p,z,,,,9 a,b,p,z,,8,, desired output: ... (1 Reply)
Discussion started by: aksijain
1 Replies

7. 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

8. 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

9. Shell Programming and Scripting

awk sort based on difference of fields and print all fields

Hi I have a file as below <field1> <field2> <field3> ... <field_num1> <field_num2> Trying to sort based on difference of <field_num1> and <field_num2> in desceding order and print all fields. I tried this and it doesn't sort on the difference field .. Appreciate your help. cat... (9 Replies)
Discussion started by: newstart
9 Replies

10. Shell Programming and Scripting

Psql output into array and read 2 fields into different variables

Hello Just edited the entry to make it easier to understand what i want How can i achieve this: GOAL: read 2 field from a table with PSQL result of this PSQL command is this INSTALLEDLANG=$(su - postgres -c "psql -A -t -q -c -d ${DBNAME} -t -c 'SELECT code, iso_code from res_lang'") ... (0 Replies)
Discussion started by: winston6071
0 Replies
Catalyst::Authentication::Store::IMAP::User(3pm)	User Contributed Perl Documentation	  Catalyst::Authentication::Store::IMAP::User(3pm)

NAME
Catalyst::Authentication::Store::IMAP::User - An authentication user for IMAP. SYNOPSIS
use Catalyst::Authentication::Store::IMAP::User; Catalyst::Authentication::Store::IMAP::User->new( id => "username", ); DESCRIPTION
This implementation of authentication user handles is supposed to go hand in hand with Catalyst::Authentication::Store::IMAP. METHODS
new( @pairs ) Create a new object with the key-value-pairs listed in the arg list. supported_features( ) Checks for existence of keys that correspond with features. for_session( ) Just returns $self, expecting it to be serializable. from_session( ) Just passes returns the unserialized object, hoping it's intact. store( ) Accessors that override superclass's dying virtual methods. id( ) check_password( $password ) Establishes a connection to the IMAP server and checks the given user credentials. Stores the Mail::IMAPClient object on the stash as imapclient for usage by other components. SEE ALSO
Hash::AsObject AUTHOR
Stefan Seifert <nine@cpan.org> LICENSE
This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2012-06-16 Catalyst::Authentication::Store::IMAP::User(3pm)
All times are GMT -4. The time now is 04:00 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy