Combining multiple files into one with the same name/different extension
I've been trying to find information in regard to creating a script that will generate HTML files. I currently have a series of files that contain code I need to surround with a <textarea> tag for easy viewing. I have about a thousand files that contain code, one file that contains the HTML code up to the textarea tag, and then a second file that contains everything from /textarea down. I need a script that will perform this process:
1) Concatenate the contents of file1.txt into an HTML file
2) Concatenate the contents of a code file into the HTML file
3) Concatenate the contents of file2.txt into the HTML
4) Set the HTML file name to the same name as the code file in step 2 with the .html extension
5) Move onto the next file
I looked around online and with a little help from another forum, I wound up with this:
Naturally, this doesn't work. Can anyone help me figure out why or perhaps offer a better way? I'm rather new to Linux, so I'd appreciate if you could be as specific and descriptive as possible. Thank you in advance.
Thank you for the reply. When I run the script, it creates one file. I'm looking for one HTML file per code file. Apparently I need the script to run equal to the number of files I have in the directory. So using your example:
| HTML HEADER | + | Firstfile.c | + | HTML tails to first two | into Firstfile.html
| HTML HEADER | + | Secondfile.c | + | HTML tails to first two | into Secondfile.html
...
...
| HTML HEADER | + | Lasttfile.c | + | HTML tails to first two | into Lastfile.html
---------- Post updated at 02:16 ---------- Previous update was at 02:05 ----------
[/COLOR]
Quote:
Originally Posted by 12o
When I run the script, it creates one file.
If you quote $FILES than the "*" does not get "translated" into filenames.
Remove the quotes and it will work.
Besides I think the "cat $f" line is unnecessary.
When the script ends, you will need to manually delete file1.txt.html, file2.txt.html and nameofyourscript.txt.html file.
Last edited by pseudocoder; 04-29-2010 at 11:40 PM..
I don't mean to nitpick your contribution, but I just wanted to point out an easy way to improve its reliability and efficiency.
That for loop list cannot handle filenames that include IFS characters (by default, this includes spaces, tabs, and newlines). Also, the egrep will not strictly match a file named "file1.txt" or "file2.txt"; "afile1.txt" would match as well.
I would suggest the following alternative, which remedies both issues and doesn't require external executables:
Finally, if you do not quote certain forms, you will get unexpected results entirely, such as with a regex:
So long story short:
1) Globs [*?] glob inside double or single quotes at the shell to expand file names,
2) Variable expansion happens inside double quotes but not single quotes.
Alister: PLEASE correct that if incorrect!!! :-}}
Quote:
Originally Posted by pseudocoder
When the script ends, you will need to manually delete file1.txt.html, file2.txt.html and nameofyourscript.txt.html file.
Hello Unix gurus,
I have a large number of files (say X) each containing two columns of data and the same number of rows.
I would like to combine these files to create a unique merged file containing X columns corresponding to the second column of each file (with a bonus of having the first... (3 Replies)
Hello Everyone,
I have 4 different files (one column in each) that I'm trying to combine into 1 file with four columns. Having issues trying to get the columns to format properly. I have tried the following:
paste file1 file2 file3 file4 | column -s $'\t' -t > results.txt
paste file1 file2... (1 Reply)
Hi
I have a file with 100 million rows. I want to split them into 1000 subfiles and name them from 1.xls to 1000.xls.. Can I do it in awk?
Thanks, (8 Replies)
I have 2 files.
each having 3 coloums
1st field date as 20130322
2nd field time as 05:55
3rd field numberic value
File 2 has entries missing for some date time.
FILE1
20130322 05:35 2219
20130322 05:40 1809
20130322 05:45 1617
20130322 05:50 ... (2 Replies)
Hello All,
I have several column files like this
$cat a_b_s1.xls
1wert
2tg
3asd
4asdf
5asdf
$cat c_d_s2.xls
1wert
2tg
3asd
4asdf
5asdf
desired put put
$cat combined.txt
s1 s2 (2 Replies)
I'm trying to combine colums from multiple file to a single file but having some issues, appreciate your help.
The filenames are the same except for the extension,
path1.m0
---------
a b c
d e f
g h i
path1.m1
---------
m n o
p q r
s t u
File names are path1.m
The... (3 Replies)
Situation:
Our system currently executes a job (COBOL Program) that generates an interface file to be sent to one of our vendors. Because this system processes information for over 100,000 employees/retirees (and growing), we'd like to multi-thread the job into processing-groups in order to... (4 Replies)
All,
I want to combine multiple files in one file.
Something like what we do on the commad line as follows ->
cat file1 file2 file3 > Main_File.
Can something like this be done in a perl script very efficiently?
Thanks,
Rahul. (1 Reply)
I have a good script to rename multiple files, but what's the best way I can remove some text from multiple filenames? Say I have a directory with 35 files with a .XLS at the end, how can I rename them to remove the .XLS but keep everything the same, without having to mv manually. Thanks. (6 Replies)