Thank you Sir!
Your code is working!
Is there any similar method to execute the same code for thousands of files??
If MadeInGermany's suggestion is working for you save it as "change.sh" (or whatever name you like, the name doesn't particularly matter), add the missing ">" characters as suggested by Aia, make it executable by issuing:
and then execute this:
check if this resembles the list of files you want to change. If not, you can "tune" your selection using various clauses of which the man-page of "find" tells you more about. Once you are satisfied with your selection replace the -ls in the line with this:
This will call the script change.sh with the filename to process as single parameter like this:
Note that processing some thousands of files can take a while and there is no diagnostic output so far. (you could add a statement to MadeInGermany's script to display the file to be processed).
This method will not be limited to any number of files.
I hope this helps.
bakunin
PS: MadeInGermany's solution didn't create an output file. Change his last line from
to this:
to create filename.xml from the input filename
after executing the code in perl using perl test.pl file*.txt, I get this error
readline() on closed filehandle $in at test.pl line 9.
Use of uninitialized value $head in concatenation (.) or string at test.pl line 10.
Use of uninitialized value $body in concatenation (.) or string at test.pl line 11.
That's a warning of some file that did not have the same format you have shown us in your post. It did not hurt anything. You should you have a .xml file for each one, even if it was not able to tag it as expected.
Did you test just a few files prior to trying the big nine yards? Did you see if what you got as a copy in xml works as expected?
I could prevent it from creating a copy of any file that does not conform to the pattern you have shown, with this:
Also, you could try the following:
This version will scan a directory for fileN.txt and save in /tmp/fileN.txt by default, or you could give it the directory that you want to scan like: perl txt2news.pl directory_with_files. You could also, change the destination in the code. By default all you have to do is perl txt2news.pl in the same directory where the files are.
it work's perfectly for single line heading but it does not work for double line heading like
Moderator's Comments:
edit by bakunin: PLEASE! When we asked you to use CODE-tags we really, definitely, finally, meant it! There is only minimal entertainment for me in the tedious task of editing them in for you and send you warnings you gladly ignore. I'd really prefer help you technically instead of dealing with such technicalities.
it work's perfectly for single line heading but it does not work for double line heading like
If your files always enclose the headings in such start- and end-tags you can do the following:
You might have to tweak the regex to allow for uppercase/lowercase inconsistencies, etc., but the basic mechanism should work for you. Note that this brings everything INCLUDING the tags into one line:
Hello, I am trying to insert a section of text between lines in another text file.
The new lines to be inserted are:
abcd.efgh.zzzz=blah
abcd.efgh.xxxx=blah
Where N = 0 to 2
Original File:
abcd.efgh.wwxx=aaaaa
abcd.efgh.yyzz=bbbbb
abcd.efgh.wwxx=aaaaa
abcd.efgh.yyzz=bbbbb... (3 Replies)
Hi!
Considering below text, how would I use sed to insert text right below the v0005-line, using the SEPARATOR-line as a pattern to search for, so two lines above the separator? I can do it right above the separator, but not 2 lines...
# v0004 - Some text
# v0005 - More text
#... (5 Replies)
Hello I'm having a little difficulty in writing a shell script for a few simple tasks.
First I have two files "file1.txt" and "file2.txt" and I want to read and compare the last line of each file. The files look like this.
File1.txt
File2.txt
After comparing the two lines I would... (2 Replies)
Hi
I am trying to insert a block of text 2 lines above a pattern match using sed
eg
#Start of file entry
{
}
#End of file entry
new bit of text has to be put in just above the } eg
#Start of file entry
{
New bit of text
}
#End of file entry (7 Replies)
Hi,
I am new to unix. I need to insert a variable which contains some lines of text into a text file after fixed number of lines..
Please help me on this..
Thanks in Advance,
Amrutha (3 Replies)
this is Korn shell unix.
The scenario is I have a pipe delimited text file which needs to be customized. say for example,I have a pipe delimited text file with 15 columns(| delimited) and 200 rows. currently the 11th and 12th column has null values for all the records(there are other null columns... (4 Replies)
I need help on how I can accomplish my task. I hope someone can help me since I've researching and trying to accomplish this for hours now. Basically, I need to comment-out (or insert a # sign in the beginning of the line) a line when the line has the specific word I am searching. Example I have... (3 Replies)
Hi ,
I need some inputs on how to open a file (file.txt) and parse the text example aaa of the file and bbb of the file and add the text zzzz once i parse (aaa and bbb) and followed by the remaining of the text as it is in the file using perl programming.
Thanks in advance (3 Replies)
Dear Folks :),
I am new to UNIX scripting and I do not know how can I insert some text in the first column of a UNIX text file at command promtp.
I can do this in vi editor by using this command :g/^/s//BBB_
e,g I have a file named as Test.dat and it containins below text:
michal... (4 Replies)