Announcement

Collapse
No announcement yet.

Batch Script to move text within file

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Batch Script to move text within file

    Hi Guys,
    This is my first post and hopefully not my last!
    I have a problem that i really hope you can help with? i need to move text within a text file from one line to a different line and location.

    Conversion Tool
    @RUN
    @UNT 1.0 1.0
    @LQT 1
    @PRD "STD" "Formula"
    @BAS "CLQD1"
    @CLR "PM 24764 RP1"
    @CAN "5 L" 4250
    @FRM 4250
    @CNT "03YEOX" 3.080209 "02WHIT" 246.416673
    @LOG
    @END

    I need to take the text from line @FRM which on this occasion is 4250 and move it to @BAS "CLQD1" so when done it will look like this.

    Conversion Tool
    @RUN
    @UNT 1.0 1.0
    @LQT 1
    @PRD "STD" “Formula"
    @BAS "CLQD1" 4250
    @CLR "PM 24764 RP1"
    @CAN "5 L" 4250
    @FRM
    @CNT "03YEOX" 3.080209 "02WHIT" 246.416673
    @LOG
    @END

    The number at @FRM could be anything from 1 to 25000 also if needed the line @FRM can keep the number also.
    I have written a script to monitor folders and move files after editing but just cannot get the grip on this.

    All help greatly appreciated.
    Last edited by grigman06; 20th August 2012, 22:21.

  • #2
    Re: biter Script to move text within file

    This biterscript will do that.

    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 }
    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

    Code:
    script "C:/Scripts/MoveText.txt"
    Don't forget to change "C:/path/to/file.abc" to appropriate file path.

    Comment

    Working...
    X