LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-20-2014, 08:24 AM   #16
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,484

Rep: Reputation: 411Reputation: 411Reputation: 411Reputation: 411Reputation: 411

Quote:
Originally Posted by grail View Post
Nice work Daniel. Here is another take using your data:
Code:
awk 'NR==FNR{for(i=1;i<NF;i+=2)arr[NR][$i]=$(i+1)}
          {for(j=1;j <= length(arr);j++){
             for(k in arr[j])
               if( $k == arr[j][k] )a++;
             if(a == length(arr[j]))print;
             a=0
          }}' f2 f1
My results were ...
Code:
awk: NR==FNR{for(i=1;i<NF;i+=2)arr[NR][$i]=$(i+1)}
awk:                                  ^ syntax error
awk: cmd. line:2:              for(k in arr[j])
awk: cmd. line:2:                          ^ syntax error
awk: cmd. line:3:                if( $k == arr[j][k] )a++;
awk: cmd. line:3:                                ^ syntax error
Is that because I'm running a back level awk?
Code:
daniel@daniel-desktop:~$ awk --version
GNU Awk 3.1.6
Copyright (C) 1989, 1991-2007 Free Software Foundation.
I'm running Ubuntu 10.04, am overdue for an upgrade, but have been reluctant to do it after hearing horror stories about problems people have after doing upgrades.

Daniel B. Martin
 
Old 01-20-2014, 08:32 AM   #17
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,252

Rep: Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685
Yes ... sorry, should have mentioned v4+ to have multi-dimensional array support
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
awk query jkeertir Linux - Newbie 3 01-17-2014 05:12 AM
[SOLVED] Awk Query gregmcc Linux - Newbie 10 08-21-2013 09:55 AM
[SOLVED] Awk query shivaa Linux - Newbie 4 12-01-2012 06:53 AM
awk query jkeertir Linux - Networking 3 04-07-2008 09:07 AM
awk program. a little query! indiancosmonaut Programming 7 07-05-2007 10:48 AM


All times are GMT -5. The time now is 03:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration