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

Report •

#1
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 <> "")
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.txt

The 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.


Report •

#2
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
I am 22 yrs old SPACE 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

:sub1
set S=%*
goto :eof


message edited by RAGAV


Report •
Related Solutions


Ask Question