If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > need help shell script

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-21-11, 11:13
dejavu4479 dejavu4479 is offline
Registered User
 
Join Date: Jul 2011
Posts: 2
need help shell script

i have 2 files, a.txt and b.txt, delimited with character |
i want to combine 2 files and the result like file output.txt
if there's missing field ini file b.txt, than the result is 'ERR'

please help me, how shell script for this case

thank you

file a.txt :
aaaa | 0001
bbbb | 0004
cccc | 0001
dddd | 0003
eeee | 0003
ffff | 0005
gggg | 0002
hhhh | 0002
iiii | 0006
jjjj | 0001
kkkk | 0001
llll | 0004
mmmm | 0005
nnnn | 0005


file b.txt :
0001 | red
0002 | yellow
0003 | blue
0004 | black
0005 | green


output :
aaaa | red
bbbb | black
cccc | red
dddd | blue
eeee | blue
ffff | green
gggg | yellow
hhhh | yellow
iiii | ERR
jjjj | red
kkkk | red
llll | black
mmmm | green
nnnn | green
Reply With Quote
  #2 (permalink)  
Old 07-21-11, 13:46
kitaman kitaman is offline
Papabi's friend
 
Join Date: Sep 2009
Location: Ontario
Posts: 629
Code:
#!/bin/ksh                                 
while read a pipe b                        
do                                         
        color=`grep $b b.txt|cut -f2 -d "|"`
        if [ "ERR$color" = "ERR" ]         
        then                               
         color="ERR"                       
        fi                                 
        echo $a "|" $color                 
done <a.txt

Last edited by kitaman; 07-21-11 at 14:25. Reason: ` missing at end of line 4
Reply With Quote
  #3 (permalink)  
Old 07-21-11, 22:48
dejavu4479 dejavu4479 is offline
Registered User
 
Join Date: Jul 2011
Posts: 2
thank you for help
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On