Computing.Net > Forums > Programming > CMD script find and replace text

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

CMD script find and replace text

Reply to Message Icon

Name: Jessica
Date: June 5, 2007 at 09:05:00 Pacific
OS: windows xp
CPU/Ram: 1gb
Product: dell
Comment:

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 4

and 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 4622

the 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



Sponsored Link
Ads by Google

Response Number 1
Name: ghostdog
Date: June 5, 2007 at 22:44:12 Pacific
Reply:

show the format of your second file.


0

Response Number 2
Name: bismarkcount
Date: June 6, 2007 at 06:52:58 Pacific
Reply:

Hello!

my first file (the one that changes) looks like this:

product 1
product 2
product 3
product 5

and 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 1410

so 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!


0

Response Number 3
Name: ghostdog
Date: June 6, 2007 at 08:53:39 Pacific
Reply:

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


0

Response Number 4
Name: Razor2.3
Date: June 6, 2007 at 20:12:25 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: CMD script find and replace text

Find and Replace text in Batch File www.computing.net/answers/programming/find-and-replace-text-in-batch-file/12413.html

Find and replace a string in a file www.computing.net/answers/programming/find-and-replace-a-string-in-a-file/19034.html

find and replace string in a file www.computing.net/answers/programming/find-and-replace-string-in-a-file/19987.html