Petri IT Knowledgebase Forums
 

Petri.co.il forums Home Forums Start Page Forums Frequently Asked Questions FAQ Member List Members List
Go Back   Petri IT Knowledgebase Forums > Windows Scripting > General Scripting
Petri.co.il is happy to award auglan the title of Most Valuable Member !!!
Register Calendar Calendar Search Petri IT Knowledgebase Forums Search Todays Posts Today's Posts Mark Forums Read

Notices

Batch Script to move text within file

Batch Script to move text within file

this thread has 1 replies and has been viewed 746 times

Closed Thread
 
Thread Tools Search this Thread Display Modes
  #1  
Old 21st August 2012, 00:05
grigman06 grigman06 is offline
Casual
Casual
 
 Join Date: Aug 2012
  6 month star
 Posts: 1
 Reputation: grigman06 is on a distinguished road (10)
Default 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; 21st August 2012 at 00:21..
  #2  
Old 13th September 2012, 19:10
PatrickMc PatrickMc is offline
Casual
Casual
 
 Join Date: Feb 2009
  6 month star 12 month star
 Posts: 9
 Reputation: PatrickMc is on a distinguished road (10)
Default 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.
Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using batch script to write\delete symbols into a text file igor7 General Scripting 1 17th October 2011 12:58
Delete first four lines form a text file using batch script vegafa69 DOS Command Shell 0 12th October 2011 20:51
Need some help with batch script - redirect output into text file igor7 General Scripting 7 25th May 2011 00:49
using batch script to delete specific lines to end of file in a text file v.prasad86 General Scripting 3 29th December 2009 00:06
using batch script to delete or modify data in a text file ttt123 General Scripting 7 24th July 2008 14:21


All times are GMT +3. The time now is 10:53.

Steel Blue 3.5.4 vBulletin Style ©2006 vBEnhanced
Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
 

Valid XHTML 1.0!   Valid CSS!

Copyright 2005 Daniel Petri