The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
help me in sending parameters from sqlplus script to unix shell script Hara Shell Programming and Scripting 2 01-29-2008 11:31 AM
Shell Script: want to insert values in database when update script runs ring Shell Programming and Scripting 1 10-25-2007 12:06 AM
here document to automate perl script that call script hogger84 Shell Programming and Scripting 3 10-22-2007 07:15 AM
returning to the parent shell after invoking a script within a script gurukottur Shell Programming and Scripting 5 09-26-2006 04:05 AM
return valuse from child script to parent script borncrazy Shell Programming and Scripting 1 08-20-2004 12:39 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-14-2008
mkw mkw is offline
Registered User
 

Join Date: May 2008
Posts: 2
Help with Script AWK

I have two files:

file1.txt
l l 0
s s 0
a a 0
a b 0
a c 0
a d 0
a e 0


file2.txt
a a 1
a b 2
a c 3
a d 4

Both this two files have 3 colums.
The file1 will have blank records and the file 2 will have values but just for some combinations.

I need to created an file3.txt that will have a blank record in case the file2 don’t have a value for that combination.

File3.txt
l l 0
s s 0
a a 1
a b 2
a c 3
a d 4
a e 4


Can anyone help me in developing this in shell script?
Thanks
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-14-2008
Smiling Dragon's Avatar
Disorganised User
 
Join Date: Nov 2007
Location: New Zealand
Posts: 714
Post

Code:
#!/bin/sh
rm -f file3.txt
while read line
do
  term=`echo $line | awk '{ print $1,$2 }'`
  value=`grep $term file2.txt | awk '{ print $3 }'`
  if [ -z "$value" ]
  then
    value="0"
  fi
  echo "$term $value" >> file3.txt
done < file1.txt
(Untested)
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:24 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0