•I am completely new to Batch Scripting •I am trying to batch merge multiple TEXT files in a single folder without having the header/Footer duplicated. •The text files are in the folder and names of text files changes, so what ever text files are in the folder will be merged. •The Master file generated from this merged file must have a HEADER and a FOOTER. Please anyone help me in this regard.. :)
Ragav, this will work. I am assuming that all text files are in folder C:/ragav and have one line header and one line footer. (Change "C:/ragav" to the correct folder in the foolowing script.)
# script merge_files.txt # Usage: script merge_files.txt var string list, file, content, header, footer var bool wroteheader # Change directory cd "C:/ragev" # Collect list of files lf -n "." "*.txt" > $list while ($list <> "") do # Get next file lex "1" $list > $file # Read file cat $file > $content # Strip header and footer lex "1" $content > $header lex "l" $content > $footer # Did we write header yet ? if ( NOT ( $wroteheader) ) echo $header > "master.txt" endif # Write this file's contents into master file. # We have already stripped off the header and footer above. echo $content >> "master.txt" done # All files are done. Write the footer echo $footer >> "master.txt"This is biterscript. Use as
script merge_files.txtThe second lex (line extractor) command has the argument "l" (l for last line). For documentation on lex command - http://www.biterscripting.com/helpp...
Hope this helps.
Very Thanks Sen Hu.. Please try out and give me the BATCH script for removing the trailing spaces in a text file.
For Eg:
My text file is like:Hai My name is Ragav SPACE SPACE SPACE
I am 22 yrs old SPACE SPACE SPACE SPACE
$ % ^&*() | SPACE SPACEI need only the text in the above lines except the trailing spaces..
The below code is working fine. But if I introduce the pipe symbol'|' in any of the line the space is not removing. Instead I find the repetition of the line containing the PIPE symbol.
@echo off > R1.txt & setLocal enableDELAYedeXpansioN
for /f "tokens=* delims= " %%a in (R2.txt) do (
call :sub1 %%a
>> R1.txt echo.!S!
)goto :eof
:sub1
set S=%*
goto :eof
message edited by RAGAV