Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi.
i am trying to use a dos script to find and replace some text, maybe look up some values, for example, i have a dinamically generated text file containing information like this:
product 1
product 2
product 3
product 4and another file with descriptions:
and i want to use the script to find the text "product 1", "product 2", etc... and replace with the name of the product and its description, so the final output would be:
product 1 MAP meal 4512
product 2 Plastic Cover 1521
product 3 Glass bowl 1412
product 4 glass dish 4622the problem is that the original text file (which contains the products) may contain only some of the products available, and i want to put their description depending on which products appear in the list.
i think i could use some find command or appending text while looping through the lines.
any help would be very appreciated

Hello!
my first file (the one that changes) looks like this:
product 1
product 2
product 3
product 5and the second file, which contains the whole catalog of descriptions, of the products which may appear in list one looks like this:
product 1 MAP meal 4512
product 2 plastic Cover 1521
product 3 glass bowl 1412
product 4 glass dish 1422
product 5 plastic spoon 1523
product 6 glass jar 1410so what i need is to make another file which contains all the products in list one and their corresponding description in list 2.
thank you in advance!

[code]
awk 'FNR==NR{
arr[$0];next
}
{
for(i in arr){
if ( $0 ~ i) {
print $0
}
}
}
' "file1" "file2"
[/code]

Here's a VBScript that does what you want. Save it as whatever.vbs
Dim fOut, sLine, lookup(255)
With CreateObject("Scripting.FileSystemObject")
With .OpenTextFile("catalog.txt")
Do Until .AtEndOfStream
sLine = Split(Trim(.ReadLine), " ", 3)
lookup(sLine(1)) = sLine(2)
Loop
End With
Set fOut = .OpenTextFile("outFile.txt", 8, True)
With .OpenTextFile("inFile.txt")
Do Until .AtEndOfStream
sLine = Split(Trim(.ReadLine))
If UCase(sLine(0)) = "PRODUCT" Then
fOut.WriteLine lookup(sLine(1))
Else
fOut.WriteLine Join(sLine)
End If
Loop
End With
End With

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |