Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combining Field from File1 to contents of File2 to form File3 1

Status
Not open for further replies.

btriggs127

Technical User
Dec 1, 2000
16
US
I am building a new file from 2 others. File1 has 8 lines, 1 Line needs the 11th and 15th field changed. That part I have. But now bring in File2, a list with 3 columns. File2.column1 needs to go into the 11th field, and File2.column2 will become the name of File3. I use C, Perl, AWK, and Different shells on my Linux Box at home, but here I use Win2K and the Awk32 Windows app, and no other programming languages. This will be used to mass create Remedy Macros for managers to see who is creating tickets every month. Sample code is as follows:

{
{if ($1 ~ /Query/ ) print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,"\"%NAME%\"", $12, $13,$14,"\"NAME\"",$16,$17,$18,$19,$20,$21,$22;else print $0}

}
That above code does the switching of the 2 fields, however I have over 100 Names to sort through in File2 and do not want to manually add them.

Any help is greatly appreciated.

Thanks
 
I don't quite understand what you want to do. Post a sample of files 1 and 2 and the output you want. CaKiwi
 
File1 is Primary Source:

opxmodxn
Set-schema: HSI:CSCTroubleTicket172.30.1.134
Query:  ( '536871119' >= "11/15/2002" AND ( '536870934' LIKE "%NAME%" OR '5' = "NAME") AND '7' != "Open" )
Form-open:
Form-entry-list: 0
Form-final: modify@
end

File2 is:
bsmith,Bill Smith,Jill Jackson
ljohnson,Larry Johnson,Darren Kelly

format of this is
UID,User's Name,Manager's Name

awk script so far is:
{
{if ($1 ~ /Query/ ) print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,"\"%NAME%\"", $12, $13,$14,"\"NAME\"",$16,$17,$18,$19,$20,$21,$22;else print $0}

}

Desired output for File3 would be:
Bill Smith
Set-schema: HSI:CSCTroubleTicket172.30.1.134
Query:  ( '536871119' >= "11/15/2002" AND ( '536870934' LIKE "%bsmith%" OR '5' = "bsmith") AND '7' != "Open" )
Form-open:
Form-entry-list: 0
Form-final: modify@
end

First line is name of the macro that will be ran by the manager in Remedy, and will be saved as BillSmith.arq.

Sorry but this about summs it up.

 
If I understand correctly, for every line in file 2 you want to create a file named from the 2nd field using file 1 as the base. This might be close to what you want.

awk -v fn1="file1" -f remed.awk file2

# ------ remed.awk ------
BEGIN {if (!fn1) fn1 = "file1"}
{
split($0,a,",")
fn3 = a[2]
gsub(/ /,"",fn3)
irec = 0
while ((getline < fn1) > 0) {
irec++
if (irec==1) {
print a[2] > fn3
}
else {
if ($1 ~ /Query/ ) {
$11 = &quot;%&quot; a[1] &quot;%&quot;
$15 = a[1]
}
print > fn3
}
}
close(fn1)
}
~ CaKiwi
 
Very close. But what is needed, is for the new files to be replicates of the base with the fields changed to reflect the database fields. But this is very close. Any additional assistance is still greatly appericiated.
 
The code you supplied:
awk -v fn1=&quot;dbfile.txt&quot; -f readfile.awk ma2.arg

Gave:
awk ERROR read.awk: can't open file &quot;&quot; for w

The directory has full permissions to everyone.

I attempted to do:
awk -v fn1=&quot;dbfile.txt&quot; -f readfile.awk dbfile.txt
as you are probably aware, this came close but no cigar. That one just duplicated the database file for each name in the database changing the first line to be that of the person's name, but the rest remained the same.
I'm at a loss.
 
Is file1 from you early posts the same as dbfile.txt and is file2 the same as ma2.arg?

Put a print statement before the split statement and post the results. CaKiwi
 
That was it, I was using different files:-( I posted the actual base file as file1 in the first post, but in running the suggestion you gave earlier, I was using the database file as the base not the actual base. So, when I changed it to:
awk -v fn1=&quot;ma2.arq&quot; -f readfile.awk dbfile.txt

It worked. ARGH! I cannot thank you enough for your assistance and patience.

Thank you again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top