Computer Hope

Software => Computer software => Topic started by: marinasc on February 01, 2019, 07:32:41 PM

Title: batch function - need to add filename at the end of each paragraph
Post by: marinasc on February 01, 2019, 07:32:41 PM
Hi, I have a bunch of text files I need to add the filename at the end of each paragraph to. There's a lot of paragraphs in each file. Ideally it would have a dash, space, then the filename (without extension) so it would look something like this: line with text - filename

Its data that i am going to port into excel, but i want the filename after each paragraph so when i have all the data in excel (I have a few hundred files) and sort them, i know what file it came from. Originally I should have created tables in word for the data, but there's so much data there now it would take me weeks (maybe longer) to convert everything into a table, adding the filenames manually. So I thought if I could add the filename at the end of each paragraph I could batch import it into excel, into one file, making it easier to track.

 I am not sure what the best way to do this is. thanks.
Title: Re: batch function - need to add filename at the end of each paragraph
Post by: Geek-9pm on February 02, 2019, 01:45:23 PM
May I make a suggestion.
Your are into using Excel for yer project, so use tools  best suited for Excel.
You will find that most often the too used is some form of:
Visual Basic for Applications.
https://en.wikipedia.org/wiki/Visual_Basic_for_Applications
Tutorial:
Getting started with VBA in Office (https://docs.microsoft.com/en-us/office/vba/library-reference/concepts/getting-started-with-vba-in-office)
Quote
The Office suite of applications has a rich set of features. There are many different ways to author, format, and manipulate documents, email, databases, forms, spreadsheets, and presentations. The great power of VBA programming in Office is that nearly every operation that you can perform with a mouse, keyboard, or a dialog box can also be done by using VBA. Further, if it can be done once with VBA, it can be done just as easily a hundred times. (In fact, the automation of repetitive tasks is one of the most common uses of VBA in Office.)

It may take yu some time to learn it, but after that you can do things much faster and better that using batch programs.

VBA is also found in Office Suites from other software companies. It is the de facto standard for programming in Office stuff.  :)

Or, yu could learn Python.   :D
 
Of course, you can do it in DOS batch. If you wish, somebody will be here shortly to help you. But be prepared to make a very clear definition of your task.
Title: Re: batch function - need to add filename at the end of each paragraph
Post by: Salmon Trout on February 03, 2019, 01:50:28 AM
We need more details of the "text file" format. Is each line terminated with an LF or CR+LF, or is each "paragraph" one long (wrapped) line? Is the marker for end-of-paragraph a blank line?
Title: Re: batch function - need to add filename at the end of each paragraph
Post by: Salmon Trout on February 03, 2019, 06:01:51 AM
Quote
I need to add the filename at the end of each paragraph
Quote
it would look something like this: line with text - filename

Do you mean you want the text appended to the last line of each paragraph, like this?

Here is the input plain text (called HGWells.txt)

Filby became pensive. "Clearly," the Time Traveller proceeded, "any
real body must have extension in _four_ directions: it must have
Length, Breadth, Thickness, and - Duration. But through a natural
infirmity of the flesh, which I will explain to you in a moment, we
incline to overlook this fact. There are really four dimensions, three
which we call the three planes of Space, and a fourth, Time. There is,
however, a tendency to draw an unreal distinction between the former
three dimensions and the latter, because it happens that our
consciousness moves intermittently in one direction along the latter
from the beginning to the end of our lives."

"That," said a very young man, making spasmodic efforts to relight his
cigar over the lamp; "that . . . very clear indeed."

"Now, it is very remarkable that this is so extensively overlooked,"
continued the Time Traveller, with a slight accession of cheerfulness.
"Really this is what is meant by the Fourth Dimension, though some
people who talk about the Fourth Dimension do not know they mean it. It
is only another way of looking at Time. _There is no difference between
Time and any of the three dimensions of Space except that our
consciousness moves along it_. But some foolish people have got hold of
the wrong side of that idea. You have all heard what they have to say
about this Fourth Dimension?"


Do you want the output text to be like this?

Filby became pensive. "Clearly," the Time Traveller proceeded, "any
real body must have extension in _four_ directions: it must have
Length, Breadth, Thickness, and - Duration. But through a natural
infirmity of the flesh, which I will explain to you in a moment, we
incline to overlook this fact. There are really four dimensions, three
which we call the three planes of Space, and a fourth, Time. There is,
however, a tendency to draw an unreal distinction between the former
three dimensions and the latter, because it happens that our
consciousness moves intermittently in one direction along the latter
from the beginning to the end of our lives." - HGWells

"That," said a very young man, making spasmodic efforts to relight his
cigar over the lamp; "that . . . very clear indeed." - HGWells

"Now, it is very remarkable that this is so extensively overlooked,"
continued the Time Traveller, with a slight accession of cheerfulness.
"Really this is what is meant by the Fourth Dimension, though some
people who talk about the Fourth Dimension do not know they mean it. It
is only another way of looking at Time. _There is no difference between
Time and any of the three dimensions of Space except that our
consciousness moves along it_. But some foolish people have got hold of
the wrong side of that idea. You have all heard what they have to say
about this Fourth Dimension?" - HGWells



Title: Re: batch function - need to add filename at the end of each paragraph
Post by: marinasc on February 05, 2019, 10:16:20 PM
Yes, let me give you examples.

The text currently looks like this:
Website 1 - www.website1.com
Website 2 - www.website2.com
Website 3 - www.website3.com

I would like it to look like this:
Website 1 - www.website1.com - filename 1
Website 2 - www.website2.com - filename 2
Website 3 - www.website3.com - filename 3 (without the extension if possible, but if that's not possible I can live with the extension)

They are regular paragraphs with regular paragraph markings. There's only 1 regular line in-between each one. Nothing fancy at all.

Thank you!!!


Title: Re: batch function - need to add filename at the end of each paragraph
Post by: Salmon Trout on February 06, 2019, 12:14:27 AM
Those are not paragraphs; they are lines.