Other Programming Languages
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreOther Programming Languages

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old May 3rd, 2007, 11:04 PM
ovince ovince is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2007
Posts: 14 ovince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 39 m 33 sec
Reputation Power: 0
Help on bash

Hi,

I have this simple awk script that cross-match 2 tables/files using for example their 3th columns

awk '{v=FNR==1?"\n":$3} NR==FNR
{a[v]=$3; b[v]=$0; next}
v in a {print b[v],$0}' fileName1 fileName2


I would like to put this function into .bashrc

function awkcrossmatch() {
tmp=$1
awk '{v=FNR==1?"\n":$tmp} NR==FNR
{a[v]=$tmp; b[v]=$0; next}
v in a {print b[v],$0}' $2 $3
}

Why this calling sequence doesnot work?

awkcrossmatch '$3' fileName1 fileName2


How to write this properly?


Thanks
oliver

Reply With Quote
  #2  
Old May 4th, 2007, 01:03 AM
DevCoach DevCoach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,188 DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 5 Days 11 h 25 m 43 sec
Reputation Power: 251
The awk string is in single quotes, so $tmp will not get replaced with the value you want. You would have to either use double quotes and escape the awk $ characters with backslashes, or build the string up by concatenating strings together.

Reply With Quote
  #3  
Old May 4th, 2007, 01:29 AM
ovince ovince is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2007
Posts: 14 ovince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 39 m 33 sec
Reputation Power: 0
Quote:
Originally Posted by DevCoach
The awk string is in single quotes, so $tmp will not get replaced with the value you want. You would have to either use double quotes and escape the awk $ characters with backslashes, or build the string up by concatenating strings together.




I hope I understood correctly. I did this change

function awkcrossmatch() {
tmp=$1
awk "{v=FNR==1?"\n":\$tmp} NR==FNR
{a[v]=\$tmp; b[v]=\$0; next}
v in a {print b[v],\$0}" $2 $3
}


But steel it does not work.

Reply With Quote
  #4  
Old May 5th, 2007, 04:48 AM
xnemesis64 xnemesis64 is offline
Google's No1 Supporter!
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2007
Location: irc.superirc.info
Posts: 569 xnemesis64 User rank is First Lieutenant (10000 - 20000 Reputation Level)xnemesis64 User rank is First Lieutenant (10000 - 20000 Reputation Level)xnemesis64 User rank is First Lieutenant (10000 - 20000 Reputation Level)xnemesis64 User rank is First Lieutenant (10000 - 20000 Reputation Level)xnemesis64 User rank is First Lieutenant (10000 - 20000 Reputation Level)xnemesis64 User rank is First Lieutenant (10000 - 20000 Reputation Level)xnemesis64 User rank is First Lieutenant (10000 - 20000 Reputation Level)xnemesis64 User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 4 Days 15 h 48 m 12 sec
Reputation Power: 145
Send a message via MSN to xnemesis64 Send a message via Yahoo to xnemesis64 Send a message via Google Talk to xnemesis64 Send a message via Skype to xnemesis64
Bash? As in Linux Bash? You might want to move over to the linux forums
__________________
Did this post help? Please Click The Next To My Post
Need help? Did you try Google?
Take a look over at my current work in progress http://crispycrisp.org

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreOther Programming Languages > Help on bash


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway