PatrickMc

Forum Replies Created

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • Avatar
    PatrickMc
    Member
    in reply to: Batch Script to move text within file #353670

    Re: biter Script to move text within file

    This biterscript will do that.

    # Script MoveText
    # Set file name
    var str file
    set $file = “C:/path/to/file.abc”
    # Read entire file in.
    var str content
    cat $file > $content

    # Extract (and remove) text after [B]@FRM[/B] and before newline.
    var str movedText
    # We will use a temporary string variable for content movement.
    var str temp
    [COLOR=red]stex[/COLOR] -c “^[B]@FRM^][/B][B]” [/B]$content > $temp
    [COLOR=red]stex[/COLOR] “]^n^” $content > $movedText
    set $content = $temp+$content

    # Insert $movedText before newline, after [B]@BAS[/B].
    # Again we will use the temporary string variable.
    [COLOR=red]stex[/COLOR] -c “^[B]@BAS^][/B][B]” [/B]$content > $temp
    [COLOR=red]set[/COLOR] $content = $temp + $movedText + $content

    # Write content back to file.
    [COLOR=black]echo[/COLOR] $content > { echo $file }
    [/CODE]

    I have not tested this code. bs is good for massive file content manipulation like this on tons of files at once. Download it from [URL]http://www.biterscripting.com[/URL]

    Save the script in file C:/Scripts/MoveText.txt. Execute it with

    [CODE]
    script “C:/Scripts/MoveText.txt”
    [/CODE]

    [COLOR=red]Don’t forget to change “C:/path/to/file.abc” to appropriate file path.[/COLOR][CODE]
    # Script MoveText
    # Set file name
    var str file
    set $file = “C:/path/to/file.abc”
    # Read entire file in.
    var str content
    cat $file > $content

    # Extract (and remove) text after @FRM and before newline.
    var str movedText
    # We will use a temporary string variable for content movement.
    var str temp
    stex -c “^@FRM^]$content > $temp
    stex “]^n^” $content > $movedText
    set $content = $temp+$content

    # Insert $movedText before newline, after @bas.
    # Again we will use the temporary string variable.
    stex -c “^@bas^]$content > $temp
    set $content = $temp + $movedText + $content

    # Write content back to file.
    echo $content > { echo $file }
    [/CODE]

    I have not tested this code. bs is good for massive file content manipulation like this on tons of files at once. Download it from http://www.biterscripting.com

    Save the script in file C:/Scripts/MoveText.txt. Execute it with

    script “C:/Scripts/MoveText.txt”
    [/CODE]

    [COLOR=red]Don’t forget to change “C:/path/to/file.abc” to appropriate file path.[/COLOR][CODE]
    script “C:/Scripts/MoveText.txt”
    [/CODE]

    Don’t forget to change “C:/path/to/file.abc” to appropriate file path.

    Avatar
    PatrickMc
    Member
    in reply to: Script to monitoring file date and then send email #353669

    Re: Script to monitoring file date and then send email

    Possibly alternative script.

    # Script FileMonitor.txt
    var string filepath, time10mins
    while (true)
    do
    # Create a time stamp for 10 mins earlier.
    set $time10mins = addtime( diff( “-1000” ) )
    # Get time stamp for the file.
    af $filepath > null
    # Is file’s timestamp less than 10 mins ?
    if ($fmtime < $time10mins)
    do
    # SEND NEGATIVE EMAIL
    done
    else
    do
    # SEND POSITIVE EMAIL
    done
    endif

    # Sleep 60 seconds.
    sleep 60
    done
    [/CODE]

    Script in biterscripting. Save script in file C:/Scripts/FileMonitor.txt. call the script with this command,

    [CODE]
    script "C:/Scripts/FileMonitor.txt" filepath( "C:/Folder/File.ext" )
    [/CODE]

    Use the correct file path in place of [COLOR=red]"C:/Folder/File.ext" [/COLOR][COLOR=black].[/COLOR]

    [COLOR=#000000]Also, use your script to send email in place of [COLOR=red]SEND POSITIVE EMAIL[/COLOR] and [COLOR=red]SEND NEGATIVE EMAIL[/COLOR].[/COLOR]

    [COLOR=#000000]Check out the help pages for addtime() etc. here http: //www .biterscripting .com/helppages/addtime.html.[/COLOR][CODE]
    # Script FileMonitor.txt
    var string filepath, time10mins
    while (true)
    do
    # Create a time stamp for 10 mins earlier.
    set $time10mins = addtime( diff( “-1000” ) )
    # Get time stamp for the file.
    af $filepath > null
    # Is file’s timestamp less than 10 mins ?
    if ($fmtime < $time10mins)
    do
    # SEND NEGATIVE EMAIL
    done
    else
    do
    # SEND POSITIVE EMAIL
    done
    endif

    # Sleep 60 seconds.
    sleep 60
    done
    [/CODE]

    Script in biterscripting. Save script in file C:/Scripts/FileMonitor.txt. call the script with this command,

    script “C:/Scripts/FileMonitor.txt” filepath( “C:/Folder/File.ext” )
    [/CODE]

    Use the correct file path in place of [COLOR=red]”C:/Folder/File.ext” [/COLOR][COLOR=black].[/COLOR]

    [COLOR=#000000]Also, use your script to send email in place of [COLOR=red]SEND POSITIVE EMAIL[/COLOR] and [COLOR=red]SEND NEGATIVE EMAIL[/COLOR].[/COLOR]

    [COLOR=#000000]Check out the help pages for addtime() etc. here http: //www .biterscripting .com/helppages/addtime.html.[/COLOR][CODE]
    script “C:/Scripts/FileMonitor.txt” filepath( “C:/Folder/File.ext” )
    [/CODE]

    Use the correct file path in place of “C:/Folder/File.ext” .

    Also, use your script to send email in place of SEND POSITIVE EMAIL and SEND NEGATIVE EMAIL.

    Check out the help pages for addtime() etc. here http: //www .biterscripting .com/helppages/addtime.html.

    Avatar
    PatrickMc
    Member
    in reply to: Getting answer from vb-script with DOS bat files #353668

    Re: Getting answer from vb-script with DOS bat files

    Quote:
    Hi. I was wondering if you could use a bat file to call an external vb-script and get the answer. If so, how? I want the answer to be private, so no writing to files.

    You can use windows biterscripting to get the output from the vbscript as follows.

    var string output
    system “C:/path/to/script.vbs” > $output
    if ($output == “YES”)
    # Do something.
    echo “something”
    else
    # Do something else.
    echo “something else”
    endif
    [/CODE]

    Can try by downloading from http: //www .biterscripting .com.[CODE]
    var string output
    system “C:/path/to/script.vbs” > $output
    if ($output == “YES”)
    # Do something.
    echo “something”
    else
    # Do something else.
    echo “something else”
    endif
    [/CODE]

    Can try by downloading from http: //www .biterscripting .com.

    Avatar
    PatrickMc
    Member
    in reply to: bat to copy file and append date – HELP #353667

    Re: bat to copy file and append date – HELP

    You want to copy file D:SecurePaySendbroker.csv to D:Adjility-Netsuite APIBackup Broker File.

    Try this 3-line script.

    # Script CopyTodaysFile.txt
    var str date
    set $date = { chex “8]” gettime() }
    system -s (“xcopy /s /c /d /e /h /i /r /y /K /O D:/SecurePay/Send/broker.csv D:/Adjility-Netsuite API/Backup Broker File/”+$date+”/broker.csv”)
    [/CODE]

    [COLOR=#000000]Script in biterscripting ( http: //www .biterscripting .com[/URL] ) . Save in file “C:/Scripts/CopyTodaysFile.txt”, and run with this command.[/COLOR]

    [CODE]script “C:/Scripts/CopyTodaysFile.txt[/CODE][COLOR=#000000]”[/COLOR][CODE]
    # Script CopyTodaysFile.txt
    var str date
    set $date = { chex “8]” gettime() }
    system -s (“xcopy /s /c /d /e /h /i /r /y /K /O D:/SecurePay/Send/broker.csv D:/Adjility-Netsuite API/Backup Broker File/”+$date+”/broker.csv”)
    [/CODE]

    Script in biterscripting ( http: //www .biterscripting .com[/URL] ) . Save in file “C:/Scripts/CopyTodaysFile.txt”, and run with this command.

    script “C:/Scripts/CopyTodaysFile.txt[/CODE][COLOR=#000000]”[/COLOR][CODE]script “C:/Scripts/CopyTodaysFile.txt[/CODE]

    Avatar
    PatrickMc
    Member

    Re: Dos Batch file to read txt file and extract character values.

    Excellent solutions already. Here is my humble addition. I am adding comments to the script.

    # Script ExtractEmail.txt
    # Input arguments
    var str path, domain
    # path should have a value like “C:/path/to/input file.txt”.
    # domain should have a value like “xxx.com”.

    var str content, line, lastname, firstname, firstinitial
    set $wsep = “\ ”
    cat $path > $content
    while ($content “”)
    do
    lex “1” $content > $line ; wex “l” $line > $lastname
    wex “l” $line > $firstname ; chex “1” $firstname > $firstinitial
    echo ($firstinitial+$lastname+”@”+domain)
    done
    [/CODE]

    Script is in biterscripting. Save in file “C:/Scripts/ExtractEmail.txt”, run it as

    [CODE]script “C:/Scripts/ExtractEmail.txt” path(“C:/path/to/input file.txt”) domain(“xxx.com”)[/CODE]

    Use correct values for the input arguments – path and domain. It will output

    [NoParse][email protected]
    [email protected][/NoParse]

    To fix case, you can use makelower() or makeupper() functions.[CODE]
    # Script ExtractEmail.txt
    # Input arguments
    var str path, domain
    # path should have a value like “C:/path/to/input file.txt”.
    # domain should have a value like “xxx.com”.

    var str content, line, lastname, firstname, firstinitial
    set $wsep = “\ “
    cat $path > $content
    while ($content “”)
    do
    lex “1” $content > $line ; wex “l” $line > $lastname
    wex “l” $line > $firstname ; chex “1” $firstname > $firstinitial
    echo ($firstinitial+$lastname+”@”+domain)
    done
    [/CODE]

    Script is in biterscripting. Save in file “C:/Scripts/ExtractEmail.txt”, run it as

    script “C:/Scripts/ExtractEmail.txt” path(“C:/path/to/input file.txt”) domain(“xxx.com”)[/CODE]

    Use correct values for the input arguments – path and domain. It will output

    [NoParse][email protected]
    [email protected][/NoParse]

    To fix case, you can use makelower() or makeupper() functions.[CODE]script “C:/Scripts/ExtractEmail.txt” path(“C:/path/to/input file.txt”) domain(“xxx.com”)[/CODE]

    Use correct values for the input arguments – path and domain. It will output

    [NoParse][email protected]
    [email protected][/NoParse]

    To fix case, you can use makelower() or makeupper() functions.

    Avatar
    PatrickMc
    Member

    Re: using batch script to delete specific lines to end of file in a text file

    Quote:
    I want to delete the lines from “DROP DOWN” to end of file. There are many files with the similiar situatiion in a directory and the names of the files are starting with delete and dondelete. I want to delete these lines from all the files.

    # Script DropDown.txt
    var str list, file, content
    # Go to the directory where files are.
    cd “/path/to/the/directory/where/files/are
    # Collect a list of files whose names begin with “delete” and “dontdelete”.
    lf -n -r “delete*” > $list ; lf -n -r “dontdelete*” >> $list
    # Go thru files in the list one by one.
    while ($list “”)
    do
    # Get the next file.
    lex “1” $list > $file
    # Get the contents of the file into a string variable.
    cat $file > $content
    # Cut out everything after “DROP DOWN”.
    stex -c “[^DROP DOWN^” $content > null
    # Write the updated $content back to the file.
    echo $content > { echo $file }
    done
    [/CODE]

    Script is in biter scripting language ( http: //www .biterscripting .com). Copy and paste the script into file C:/Scripts/DropDown.txt, then enter the following command into biterscripting.

    [CODE]script “C:/Scripts/DropDown.txt”[/CODE]

    Please test the script first before using on real files.[CODE]
    # Script DropDown.txt
    var str list, file, content
    # Go to the directory where files are.
    cd “/path/to/the/directory/where/files/are
    # Collect a list of files whose names begin with “delete” and “dontdelete”.
    lf -n -r “delete*” > $list ; lf -n -r “dontdelete*” >> $list
    # Go thru files in the list one by one.
    while ($list “”)
    do
    # Get the next file.
    lex “1” $list > $file
    # Get the contents of the file into a string variable.
    cat $file > $content
    # Cut out everything after “DROP DOWN”.
    stex -c “[^DROP DOWN^” $content > null
    # Write the updated $content back to the file.
    echo $content > { echo $file }
    done
    [/CODE]

    Script is in biter scripting language ( http: //www .biterscripting .com). Copy and paste the script into file C:/Scripts/DropDown.txt, then enter the following command into biterscripting.

    script “C:/Scripts/DropDown.txt”[/CODE]

    Please test the script first before using on real files.[CODE]script “C:/Scripts/DropDown.txt”[/CODE]

    Please test the script first before using on real files.

    Avatar
    PatrickMc
    Member
    in reply to: URGENT: Need help on Batch file. #353664

    Re: URGENT: Need help on Batch file.

    I understand the requirement is in batch, but it can severely limit you. Any scripting language will offer a lot more benefit. Here are the answers.

    1. Extracting Field4 and Field5 values into Var and Var1.

    # Read file in.
    var str file, Var, Var1 ; cat “x.txt” >$file
    stex -c “^Field4=”^]” $file > null ; stex -c “]^”^” $file > $Var
    stex -c “^Field5=”^]” $file > null ; stex -c “]^”^” $file > $Var1
    echo $Var $Var1
    [/CODE]

    [B]2. Check if 8th digit of variable v1 is double quote.[/B]

    (I think you mean 8th digit, not 8th bit.)

    [CODE]
    if ( { chex “8” $v1 } == “”” )
    echo “8th digit of v1 is double quote.”
    endif
    [/CODE]

    [B]3. Usage of double quote in string constants.[/B]

    Escape it with backslash, as, “.

    Both above codes show that.

    The above code fragments are in biterscripting. But any scripting language will do. biterscripting probably comes closest the native unix and linux scripting. You can call the scripts from DOS batch as follows.

    [CODE]biterscripting.exe scriptfile.txt[/CODE]

    The commands I used are stex=string extractor and chex=character extractor. Their help pages are at http: //www .biterscripting .com/helppages/stex.html and http: //www .biterscripting .com/helppages/chex.html.

    Patrick[CODE]
    # Read file in.
    var str file, Var, Var1 ; cat “x.txt” >$file
    stex -c “^Field4=”^]” $file > null ; stex -c “]^”^” $file > $Var
    stex -c “^Field5=”^]” $file > null ; stex -c “]^”^” $file > $Var1
    echo $Var $Var1
    [/CODE]

    2. Check if 8th digit of variable v1 is double quote.

    (I think you mean 8th digit, not 8th bit.)

    if ( { chex “8” $v1 } == “”” )
    echo “8th digit of v1 is double quote.”
    endif
    [/CODE]

    [B]3. Usage of double quote in string constants.[/B]

    Escape it with backslash, as, “.

    Both above codes show that.

    The above code fragments are in biterscripting. But any scripting language will do. biterscripting probably comes closest the native unix and linux scripting. You can call the scripts from DOS batch as follows.

    [CODE]biterscripting.exe scriptfile.txt[/CODE]

    The commands I used are stex=string extractor and chex=character extractor. Their help pages are at http: //www .biterscripting .com/helppages/stex.html and http: //www .biterscripting .com/helppages/chex.html.

    Patrick[CODE]
    if ( { chex “8” $v1 } == “”” )
    echo “8th digit of v1 is double quote.”
    endif
    [/CODE]

    3. Usage of double quote in string constants.

    Escape it with backslash, as, “.

    Both above codes show that.

    The above code fragments are in biterscripting. But any scripting language will do. biterscripting probably comes closest the native unix and linux scripting. You can call the scripts from DOS batch as follows.

    biterscripting.exe scriptfile.txt[/CODE]

    The commands I used are stex=string extractor and chex=character extractor. Their help pages are at http: //www .biterscripting .com/helppages/stex.html and http: //www .biterscripting .com/helppages/chex.html.

    Patrick[CODE]biterscripting.exe scriptfile.txt[/CODE]

    The commands I used are stex=string extractor and chex=character extractor. Their help pages are at http: //www .biterscripting .com/helppages/stex.html and http: //www .biterscripting .com/helppages/chex.html.

    Patrick

    Avatar
    PatrickMc
    Member

    Re: Batch Scripting – how to read a string value from a text file

    Simple, really. I will assume your input file is at C:Input.txt (change this name in the script below).

    Code:
    # Script names.txt
    # Read input file into str variable.
    var str input ; cat “C:Input.txt” > $input

    # Repeatedly extract strings between Name=” and ” .
    while ( { sen -c -r “^Name=&”&”^” $input } > 0 )
    do
    # Remove portion upto Name=” .
    stex -c “^Name=”^]” $input > null
    # Print portion upto ” .
    stex -c “]^”^” $input
    done

    Save the script as C:Scriptsnames.txt. Script is in biterscripting. Start biterscripting (download free from http: //www .biterscripting .com), and enter the following command.

    Code:
    script names.txt

    You will see all names one per line. To save output to C:TestFile.txt, redirect the output of the script as follows.

    Code:
    script names.txt > “C:TestFile.txt”

    Should do it.

    Patrick

    Avatar
    PatrickMc
    Member
    in reply to: DOS Batch file for searching a specific file #353662

    Re: DOS Batch file for searching a specific file

    Hi Pmg:

    I use biterscripting (http: //www .biterscripting .com for free download) instead of DOS. You may want to try it too. Here are a couple of suggestions to get you started.

    The following command in biterscripting will list all files with .txt extension in directory C:/Data .

    find -n “C:/Data/*.txt”

    If you want to recursively search subdirectories, use the -r flag, as follows.

    find -r -n “C:/Data/*.txt”

    For more control, use something like the following.

    find -r -n “*.txt” “C:/Data” ($fctime > “20090226”)

    The above will list all files with extension .txt in directory C:/Data (and subdirectories) that were created after Feb 26, 2009.

    To do something with each file in the list of files, use something like the following:

    var str file, list
    find -r -n “*.txt” “C:/Data” ($fctime > “20090226”) > $list
    while ($list “”)
    do
    lex “1” $list > $file
    cat $file
    done

    The above just types the contents of each file to screen, using the cat command. But you can do other things with each file in the while-do-done loop.

    Hope this helps.

    Patrick Mc

Viewing 9 posts - 1 through 9 (of 9 total)