954,292 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Text File Editing Help Required.

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.

coolvision
Light Poster
29 posts since Jan 2007
Reputation Points: 10
Solved Threads: 0
 

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)

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

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.

coolvision
Light Poster
29 posts since Jan 2007
Reputation Points: 10
Solved Threads: 0
 

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.

MidiMagic
Nearly a Senior Poster
3,319 posts since Jan 2007
Reputation Points: 730
Solved Threads: 182
 

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.

coolvision
Light Poster
29 posts since Jan 2007
Reputation Points: 10
Solved Threads: 0
 

Just make sure you unzip it first.

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

Attachments thweeze.zip (135.64KB)
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

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.

ghostdog74
Junior Poster
156 posts since Apr 2006
Reputation Points: 75
Solved Threads: 44
 

I get the error...

%%i was unexpected at this time
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

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

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

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
ghostdog74
Junior Poster
156 posts since Apr 2006
Reputation Points: 75
Solved Threads: 44
 

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?

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

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.

ghostdog74
Junior Poster
156 posts since Apr 2006
Reputation Points: 75
Solved Threads: 44
 

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.

coolvision
Light Poster
29 posts since Jan 2007
Reputation Points: 10
Solved Threads: 0
 

No probs :)

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

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,

coolvision
Light Poster
29 posts since Jan 2007
Reputation Points: 10
Solved Threads: 0
 

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...

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

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.

Attachments thweetiepie.zip (139.45KB)
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

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,

coolvision
Light Poster
29 posts since Jan 2007
Reputation Points: 10
Solved Threads: 0
 

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. :)

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

Ok Dear, thanks for your co-operation.

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

Thanks & Regards,

coolvision
Light Poster
29 posts since Jan 2007
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You