Results 1 to 10 of 12
I am sure some of you guys are getting tired of my questions. However, I have yet another one . I promise a drink on me for this one
What ...
- 10-23-2007 #1Just Joined!
- Join Date
- Oct 2007
- Location
- Houston
- Posts
- 75
Adding Text
I am sure some of you guys are getting tired of my questions. However, I have yet another one
. I promise a drink on me for this one 
What I am trying to do is make one file full of a list of customer names and their account numbers. Then I will have another file which I will call status that has a bunch of lines in there with various different things. What I want to do is anytime I see an account number in the status file I want to put the customer name in front of it.
Example of current setup:
Customer File
Status FileCode:R#####1 Customer One R#####2 Customer Two R#####3 Customer Three
Code:R#####1 Some info Some info2 Some info3 etc R#####2 Some info some info22 R#####3 Some info Some more info some more infox2 some more infox3
My desired results
What I was thinking of doing was making a file full of sed s/R#####1/Customer One R#####1/g I didn't think that would be practical so I came to the best place to ask questions.Code:Customer One R#####1 Some info Some info2 some info3 Customer Two R#####2 Some info someinfo222 Customer Three R#####3 Some info Some more info some more infox2 some more infox3
- 10-23-2007 #2Code:
% cat customer R#####1 Customer One R#####2 Customer Two R#####3 Customer Three % cat status R#####1 Some info Some info2 Some info3 etc R#####2 Some info some info22 R#####3 Some info Some more info some more infox2 some more infox3 % awk 'NR==FNR{cust[$1]=$2FS$3;next} $1 in cust{$0=cust[$1]FS$0}1' customer status Customer One R#####1 Some info Some info2 Some info3 etc Customer Two R#####2 Some info some info22 Customer Three R#####3 Some info Some more info some more infox2 some more infox3
- 10-23-2007 #3Just Joined!
- Join Date
- Oct 2007
- Location
- Houston
- Posts
- 75
This is not working correctly. It is not replacing data. Could it be because the customers have spaces some times? or there is a space in the customer file from the account R######
- 10-23-2007 #4
Yes, it doesn't replace anything; it only outputs.
To change your file:
Code:awk 'NR==FNR{cust[$1]=$2FS$3;next} $1 in cust{$0=cust[$1]FS$0}1 ' customer status>status_new\ &&mv status status.orig\ &&mv status_new statusLast edited by radoulov; 10-23-2007 at 08:36 PM. Reason: corrected
- 10-23-2007 #5
- 10-23-2007 #6Just Joined!
- Join Date
- Oct 2007
- Location
- Houston
- Posts
- 75
You know what my fault for once again not giving a real life example. I figured out why it was not doing it. I had set the example file I used (I cleaned it wierd ly) but the orginial file has a space then * and then space and tab. Looks like
Code:* R#### Maint 1.0.0.1 Active Some of the Backup Sets have not run since Oct 20, 2007
- 10-23-2007 #7
- 10-23-2007 #8Just Joined!
- Join Date
- Oct 2007
- Location
- Houston
- Posts
- 75
Correct. The status file is the example I gave in my last post. The customer file looks just as I posted it;
R##### Customer Name
- 10-23-2007 #9
Assuming R##### (5 #) in the customer file and R#### (4 #) in the status file:
If there are no spaces in the customer name, you can avoid all that $2FS$3,Code:awk 'NR==FNR{cust[$1]=$2FS$3;next} $2"#" in cust{$0=cust[$2"#"]FS$0}1
it must be only $2.
- 10-23-2007 #10Just Joined!
- Join Date
- Oct 2007
- Location
- Houston
- Posts
- 75
the R###### is actually an R100001 it is an actual number. The status file has the same information they are both 12 characters long. The numbers are different.


Reply With Quote
