Computing.Net > Forums > Windows XP > Dos Append Text to a given line

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Dos Append Text to a given line

Reply to Message Icon

Name: madmapper07
Date: March 17, 2008 at 04:59:05 Pacific
OS: XP Pro - V 2002 SP2
CPU/Ram: Intel(R) Pentium(R) D CPU
Product: Dell
Comment:

Hi
I am working on a validation routine for some GIS data tables that I have. The table that I am interested in appending text to is Table.tab (which can be edited in Notepad).
The format of the Table is:-

!table
!version 650
!charset WindowsLatin1

Definition Table
Type NATIVE Charset "WindowsLatin1"
Fields 5
a char (10);
b char (10);
c char (10);
d char (10);
e char (10);

I would like to append the text Readonly
against d char (10); so that after running the line will read

d char (10) readonly;

The position of the line is always line 11 of Table.tab. Can anyone help?
Thanks



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: March 17, 2008 at 05:22:44 Pacific
Reply:

@echo off > newfile
setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in (table.tab) do (
echo %%a |find "d char" > nul
if not errorlevel 1 ( echo %%a readonly >> newfile
) else (
echo %%a >> newfile
)
)


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 2
Name: madmapper07
Date: March 17, 2008 at 08:01:48 Pacific
Reply:

Thanks for this

I must be doing something wrong though as i keep getting %%a not expected at this time


0

Response Number 3
Name: Mechanix2Go
Date: March 18, 2008 at 01:31:45 Pacific
Reply:

Did you paste it in?


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 4
Name: madmapper07
Date: March 18, 2008 at 04:35:43 Pacific
Reply:

Thanks for your help, I have got that bit working - just a couple of questions, I'm afraid. My file format has changed and the line I want to change has subsequently changed to -

Request5 Char (10) ;

when I change the code above to find "Request5 Char" the newfile that the code produces changes the line to:-

Request5 Char (10) ; Readonly

I need the readonly to appear between "(10)" and ";" i.e.:-

Request5 Char (10) Readonly ;

Another problem encountered is that I lose the exclamation marks at the top of the file - new file removes them so the top 3 lines in newfile are

table
version 650
charset WindowsLatin1

my data needs them to be

!table
!version 650
!charset WindowsLatin1

Any ideas on how I can achieve this?

Thanks Mark


0

Response Number 5
Name: Mechanix2Go
Date: March 19, 2008 at 06:17:31 Pacific
Reply:

We may be getting close. Post a copy of the current table.tab file.

::== T7.bat

@echo off > newfile
setLocal

for /f "tokens=* delims= " %%a in (table.tab) do (
echo %%a |find "d char" > nul
if not errorlevel 1 (
echo Request5 Char ^(10^) readonly; >> newfile
) else (
echo %%a >> newfile
)
)

::

::== end T7.bat


=====================================
If at first you don't succeed, you're about average.

M2


0

Related Posts

See More



Response Number 6
Name: madmapper07
Date: April 4, 2008 at 00:34:45 Pacific
Reply:

Sorry for the delay in getting back to you, I've been on bereavement leave.

The new code doesn't appear to do anything (What is Find "d char" looking for?)

As requested new table.tab format below-

!table
!version 650
!charset WindowsLatin1

Definition Table
Type NATIVE Charset "WindowsLatin1"
Fields 56
District_Search_Ref Char (20) ;
District_Council_ID Char (8) ;
UPRN Char (20) ;
DCC_Search_No Char (6) ;
Year Char (4) ;
Date_of_Receipt Char (10) ;
Date_of_Return Char (10) ;
FTP_to_DCC Char (30) ;
FTP_from_DCC Char (30) ;
Status Char (3) ;
Version Char (2) ;
User_ID Char (6) ;
Property_No Char (25) ;
Street Char (50) ;
Location Char (50) ;
Town Char (25) ;
Postcode Char (8) ;
RASE Char (50) ;
Q2a Char (200) ;
Q2b Char (175) ;
Q2c Char (25) ;
Q2d Char (25) ;
Q2_Clarification Char (150) ;
Q3_2 Char (80) ;
Q3_4a Char (80) ;
Q3_4b Char (80) ;
Q3_4c Char (80) ;
Q3_4d Char (80) ;
Q3_4e Char (80) ;
Q3_4f Char (80) ;
Q3_5 Char (80) ;
Q3_6a Char (125) ;
Q3_6b Char (80) ;
Q3_6c Char (80) ;
Q3_6d Char (80) ;
Q3_6e Char (80) ;
Q3_6f Char (80) ;
Q3_6g Char (125) ;
Q3_6h Char (80) ;
Q3_6i Char (125) ;
Q3_6j Char (80) ;
Q3_6k Char (80) ;
Q3_6l Char (80) ;
Q3_7 Char (100) ;
Q3_11 Char (150) ;
Request5 Char (10) ;
Q5_1 Char (10) ;
Q5_2 Char (30) ;
Request18 Char (10) ;
Q18_1 Char (30) ;
Q18_2a Char (30) ;
Q18_2b Char (50) ;
Request22 Char (10) ;
Q22_1 Char (30) ;
Q22_2 Char (50) ;
Comments Char (254) ;



0

Response Number 7
Name: Mechanix2Go
Date: April 4, 2008 at 03:47:39 Pacific
Reply:

The reason it doesn't do anything is because it's looking for "d char", which is not in the new table.

There are, however, three lines contaiining "d Char". So it alters all 3.

Question is: which of these 3 lines should be changed? And to what?:

::====================
Q2d Char (25) ;
Q3_4d Char (80) ;
Q3_6d Char (80) ;
::====================


::======================
::==t8.bat

EnableDelayedExpansion

::== t8.bat

@echo off > newfile
setLocal

for /f "tokens=* delims= " %%a in (table.tab) do (
echo %%a |find "d Char" > nul
if not errorlevel 1 (
echo Request5 Char ^(10^) readonly; >> newfile
) else (
echo %%a >> newfile
)
)

::== done



=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 8
Name: madmapper07
Date: April 4, 2008 at 03:56:28 Pacific
Reply:

None should be changed, we want to change

Request5 Char (10) ;
to
Request5 Char (10) readonly;

Thanks again for your help


0

Response Number 9
Name: Mechanix2Go
Date: April 4, 2008 at 04:03:52 Pacific
Reply:

::== t9.bat

@echo off > newfile
setLocal

for /f "tokens=* delims= " %%a in (table.tab) do (
echo %%a |find "Request5 Char" > nul
if not errorlevel 1 (
echo Request5 Char ^(10^) readonly; >> newfile
) else (
echo %%a >> newfile
)
)

::== done


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 10
Name: madmapper07
Date: April 4, 2008 at 04:24:28 Pacific
Reply:

Spot on! that's great

I really appreciate the help!


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Windows XP Forum Home


Sponsored links

Ads by Google


Results for: Dos Append Text to a given line

How do I connect to a server? www.computing.net/answers/windows-xp/how-do-i-connect-to-a-server/155804.html

Make the second line in a file to a variable? www.computing.net/answers/windows-xp/make-the-second-line-in-a-file-to-a-variable/179434.html

How do I connect to a remote computer? www.computing.net/answers/windows-xp/how-do-i-connect-to-a-remote-computer/12106.html