Hello Dears,
I have hundereds of text
files and every file have thousand of
lines and there is only one word at each
line. My problem is that I want to add a
word with every word in files.
Example:
files contains a words
hello
dani
google
yahoo
Now I want to add a word with every word
like that:
hellodear
daniweb
googleisbest
yahoodotherest
if your understad my problem plz reply me
how can I edit all of my files bcoz
manually editing will take very long
times, bcoz there is about millions words
in all files.
Thanks in Advance.

Member Avatar for iamthwee

Your example is too vague.

But you would need to write a program to do that. Give a better example and I could write it for you. (Maybe)

Thanks for reply, actually, I have thousands of text files and every file contains thousands of lines and there is only one word on each line. Now I want to add/attach one more word with every signle word in all files. For example there is a word in a file "dani" I want to convert it to "daniweb". So, like this I want to edit all my files.

It would be much appreciated if you make a programme/script for this solution.

Thanks & Regards.

How is it supposed to know which word to add?

Does it always add the same word when it finds a particular word? Or is the same word always added in the same place in the file?

Are the words to be added add in a list?

If you always need to add the same words in the same places in the file, you might be able to trick Excel into doing the job for you.

I already tried doing it with Excel, but I failed to do that, and Yes there is same single word which I want to add with every word in files.
Any other Trick ? Or Plz you try it to do with Excel or any other utility.

Member Avatar for iamthwee

Just make sure you unzip it first.

Right click on the folder and choose to unzip(extract folder)

if all you need is to add a specific word to the end of each line (which contains one word ), then a batch file will suffice. An example

@echo off
for /F  %%i in (file.txt) do echo %%iweb

This will add the word "web" to the current lines

output:

C:\test>test.bat
helloweb
daniweb
googleweb
yahooweb

If you need different specific words for each line, then its a different story.

Member Avatar for iamthwee

I get the error...

%%i was unexpected at this time
Member Avatar for iamthwee

Ah you need to wrap it up as a bat file. (Strange)

I get the error...

%%i was unexpected at this time

you got to run it in a batch file. If you run the for loop in a command shell, change %%i to %i
For ex, on command line

C:\test>@echo off
for /F  %i in (file.txt) do echo %iweb
helloweb
daniweb
googleweb
yahooweb
Member Avatar for iamthwee

Yeah I just realised.

Why would you need to change the syntax for the bat file tho?

Isn't a batch (bat) file just a mirror of syntax you would use at the command prompt?

Yeah I just realised.

Why would you need to change the syntax for the bat file tho?

Isn't a batch (bat) file just a mirror of syntax you would use at the command prompt?

I did not change the syntax. Its how variables are defined in Windows batch shell.
If you open a command prompt and work your batch commands from there using for loops, you have to use %i (or some other alphabet) as the variable. If in a batch file , use %%i.. This is how windows batch work. You can also try it out. It will give error saying "syntax of the command is incorrect" when you use %i in a batch file.

Dear iamthwee your really done a great job, and I am really thankful to you for that task. Its working as I want to do.

Member Avatar for iamthwee

No probs :)

Dear iamthwee however patch is working nice but its still taking a lot of time to editing text files, bcoz text files in diff folders and in every folder there is hundereds of files, and for editing I 1st copy file from one folder to another folder and then rename it to test and then apply patch and then cut it to another folder and again rename it and I repeat it for every signle file editing.

So, now can you plz add some more functionality by adding the patch edit all the files in signle folder and create a signle file or any named files in some other or same folder. I think this will save a lot of time instead of editing one by one file.

Hope you can do that. and I am waiting for your reply.

Thanks & Regards,

Member Avatar for iamthwee

Yes I can do this so that it applies the patch to all your files (of any particular name) within a given folder.

Please wait 20 mins, because I have to program it...

Member Avatar for iamthwee

Here we go...

Again, once you have downloaded it, right-click the folder and choose to extract all files.

When you run the patch it creates a new folder called:

NewFiles

In that folder will be your one text file.

Dear Iamthwee Thanks you very very much again.
And one more thing, is it create a duplicate free list or there may duplicate words existing ?. if yes, is it possible its create a duplicate free result file. ?

Thanks & Regards,

Member Avatar for iamthwee

It doesn't eliminate duplicates in the text file.

But there are a variety of ways to do that. Implementing a hash table/map would be one such way (reasonably efficient).

Do you want me to do that for you. :)

Ok Dear, thanks for your co-operation.

May God give a success to you in this and hereafter world.

Thanks & Regards,

Member Avatar for iamthwee

Ok give me ten minutes and you will have your final patch with the duplicates removed. :)

Member Avatar for iamthwee

Here is (wat I hope is) the final patch.

It creates a file called noduplicates .

That file happens to be sorted into alphabetical order.

It should be very efficient.

This would have been so easy in the old VW line editor. One command would have done it:

S/*/*addedword/*

I think edlin has similar powers. It's hiding in the MS-DOS part of XP.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.