Click here for important information about

Need a Windows batch Script file

October 20, 2015 at 09:59:05
Specs: Windows 7
•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.. :)

See More: Need a Windows batch Script file

October 26, 2015 at 08:54:23
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 <> "")
    # 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"

    # Write this file's contents into master file.
    # We have already stripped off the header and footer above.
    echo $content >> "master.txt"


# All files are done. Write the footer
echo $footer >> "master.txt"

This is biterscript. Use as

script merge_files.txt

The second lex (line extractor) command has the argument "l" (l for last line). For documentation on lex command -

Hope this helps.

Report •

October 29, 2015 at 05:21:21
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
$ % ^&*() | SPACE SPACE

I 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

set S=%*
goto :eof

message edited by RAGAV

Report •
Related Solutions

Ask Question