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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
pattern matching problem namishtiwari Shell Programming and Scripting 2 05-23-2008 08:33 AM
pattern matching problem rein Shell Programming and Scripting 8 10-27-2007 12:44 AM
Stuck with a simple find problem vibhor_agarwali UNIX for Dummies Questions & Answers 13 05-21-2007 08:48 AM
Sco 6 copying problem Yrr88 SCO 0 11-29-2006 05:14 PM
Copying all files of type "pdf" milage UNIX for Dummies Questions & Answers 6 07-12-2001 03:38 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-04-2008
derek3131 derek3131 is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 5
Stuck on a matching, copying type problem

Hi all, I am new to these forum and to scripting in general for that matter. i have been looking through the forums for something that could explain my problem. I have be come pretty familiar with sed and awk but I can not seem to figure this out... I am trying to match data from 3 files but every thing I have tried doesn't seem to do what i need it to. And maybe this is something better suited for perl or python ( which i have no experience with ).. ok here goes...

Problem:

1. Want to match $1b to $2a, if match copy $2b to $4a

2. Want to match $1c to $2a, if match copy $2c to $4a (and overwrite the data in $4a)


file_a is comma seperated and has 4 fields

$1a,$2a,$3a,$4a

file_b is comma seperated and has 2 fields

$1b,$2b

file_c is comma seperated and has 2 field

$1c,$2c



Here is example of the data in the files:


Code:
berserker# more file_a

gpf135cm,gpf090079cs,purple,
gpf136cm,gpf100002cs,blue,
gpf138cm,gpf100065cs,purple,
gpf140cm,gpf110005cs,purple,
gpf141cm,gpf110037cs,purple,
gpf139cm,gpf100101cs,purple,
gpf139cm,gpf100119cs,purple,

 
berserker# more file_b

hou020067cs, synopsis = Urgent message file problems reported
hou090022cs, synopsis = Urgent message file problems reported
hou090056cs, synopsis = Node was detected as causing a spike by job 16811167
hou090064cs, synopsis = Node was disabled by Jeff ext8592
gpf090079cs, synopsis = Excessive ECC errors detected
gpf100002cs, synopsis = Excessive ECC errors detected
gpf090079cs,Apr  1 20:28:20 gpf090079cs kernel: MC1: CE page 0x1ac685 offset 0x240 grain 8 syndrome 0x4a row 0 channel 0 label "": bluesmoke_k8
gpf100002cs, 


berserker# more file_c

gpf090079cs MC1: row 0 channel 0



So far I have figured out how to extract all this information and organize it in these files using AWK and SED, but I am not sure that I can get it to do this type of problem... Any help on this problem that i have been beating on my keyboard for would be greatly appreciated. Thank you

Last edited by Yogesh Sawant; 04-04-2008 at 09:39 AM.. Reason: added code tags
  #2 (permalink)  
Old 04-05-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
The join command is a completely generic solution to this type of problem. However, it requires input files to be sorted. You could create awk scripts which read in one file in the BEGIN part and then processes the other as its regular input. Perl or Python might suit themselves better to this type of problem, though. Learning the basics of Perl is not particularly challenging if you are already familiar with sed and awk.
  #3 (permalink)  
Old 04-07-2008
derek3131 derek3131 is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 5
Cool, thanks for you reply Era. I in fact went to a half-priced book store this weekend and picked up O'reilly's Learning Perl Third edition for 5 bucks, I think the newest edition is four. So I am sure it will be find.
  #4 (permalink)  
Old 04-07-2008
ag79 ag79 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 33
i see that at any point of time, you'll be handling two files. since you're familiar with awk, the following may work for you, even though I agree perl might be a better tool for the job.

for FILE_1 in file_b file_c
do

#Read file_a line by line
while read file1line
do
#Extract the column from file_b or file_c that you want to compare to in file a
coltocompare_bc=`awk blah blah`

#Here, get the column from file a
coltocompare_a=`awk blah blah`

#Here compare coltocompare_bc and coltocompare_a and do what you like.
echo "Maybe this will work, maybe not"

done < FILE_1

done
  #5 (permalink)  
Old 04-14-2008
derek3131 derek3131 is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 5
Good gravy, why and i not getting how to do this seemingly simple problem? I really feel that I am making this harder then it needs to be..


Code:
#!/usr/bin/perl
#
$data = 'hou100cm,hou010008cs,purple
hou132cm,hou090026cs,purple
hou133cm,hou090057cs,purple
hou134cm,hou090064cs,blue
hou190cm,hou230095cs,blue
hou193cm,hou240058cs,purple
hou195cm,hou240124cs,purple
hou195cm,hou240125cs,purple
gpf132cm,gpf090013cs,purple
gpf132cm,gpf090028cs,purple
gpf133cm,gpf090036cs,purple
gpf133cm,gpf090051cs,blue
gpf133cm,gpf090059cs,purple
gpf134cm,gpf090067cs,purple
gpf134cm,gpf090079cs,blue
gpf136cm,gpf100002cs,blue
gpf136cm,gpf100003cs,purple
gpf136cm,gpf100024cs,blue
gpf141cm,gpf110059cs,blue
gpf139cm,gpf100099cs,blue
gpf139cm,gpf100100cs,purple
gpf139cm,gpf100101cs,purple';

$blue = 'gpf100024cs, MC1: row 1 channel 1
gpf100002cs, Bad DIMM slot (motherboard)
gpf090079cs, MC1: row 0 Channel 0
hou230095cs, Urgent message file problems reported
hou090064cs,  NODE USE DISABLED BY Jeff';

(master, node, status) = split(',', $data);
(node2,desc) = split(',', $blue);

I have tried to match $blue{$node2} =~ $data{$node} ;

then join($blue{$desc}) to $data for days now, i think i am confusing myself sense I think I have come up with at least 5 different ways that I thought would work on this... but no luck...

Can someone tell me what I am doing wrong here, my eyes have grown tired and my mind numb, please help if you can.

Basically two files $data and $Blue
Data has 0,1,2 fields and Blue has 0 and 1 field.
If $blue{field0} =~ $data{field1}, then copy or move $blue{field1} to $data{field3}. And of course field3 is newly created.

thank you for anyhelp .

Last edited by derek3131; 04-15-2008 at 09:12 AM..
Closed Thread

Bookmarks

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:04 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0