Use change.com andTokeniser to ignore spaces

September 8, 2010 at 21:47:19
Specs: Windows XP
I want to change the string in the file..

First i used

change tnsnames.ora "(Host = HXXX)(Port = 1500))" "(Host = MAAA)(Port = 2555))"

But In case "(Host = HXXX)(Port = 1500))" have some space.this does not works.

Now I tried
FOR /F "tokens=* delims= " %%G IN ('N:\tnsnames.ora') DO (
for /f "tokens=* delims= " %%a in ("(Host = HXXX)(Port = 1500))") do

(
Copy %%a zzzz
change zzzz "%%a" "(Host = MAAA)(Port = 2555))"
)

)

Please guide me with this..


See More: Use change.com andTokeniser to ignore spaces

Report •


#1
September 9, 2010 at 00:02:04
show properly your
1) input file
2) expected output

describe clearly what you want to do

GNU win32 packages | Gawk


Report •

#2
September 9, 2010 at 01:21:53
This is the text in some file TEXT1= "(Host = HXXX)(Port = 1500))"
I want to change with this.TEXT 2 = (Host = MAAA)(Port = 2555))

I can do this by using change.com.
But If text one has some space.eg ="(Host = HXXX) ( Port = 1500))"

Change .com command does not work.

I want to replace the text in a text file .even if the text have some space .

so I thought may be I can use tokens to egnore spaces between text1.and change text1 with text2


Report •

#3
September 9, 2010 at 04:42:57
Try this, I haven't tested it, and I'm not sure why you used copy. But since you did, I used it to.

FOR /f "tokens=*" %%a IN ("Findstr ".*Host.*.*HXXX.*Port.*.*1500.*" "FileName.txt"') DO (
	SET Var=%%a
)
IF "%Var: =%"=="(Host=HXXX)(Port=1500))" (
	Copy %Var% zzzz
	CHANGE zzzz "%Var%" "(Host = MAAA)(Port = 2555))"
)

Can I put a question here?


Report •

Related Solutions

#4
September 9, 2010 at 05:23:26
It did not worked.You can give me your Idea.

My requirement is to change
(Host=mac)(Port=2530))
to
(Host=XXX)(Port=1500))
in c:\aman\abc.txt file.

and
(Host=mac)(Port=2530)) can be
With spaces like following:-
(Host =mac)(Port=2530))
(Host=mac) (Port=2530))
(Host=mac)(Port =2530))
(Host=mac)(Port= 2530))

Plz help...


Report •

#5
September 9, 2010 at 05:27:23
@echo off
SetLocal EnableDelayedExpansion

FOR /f "tokens=*" %%a IN ("Findstr ".*Host.*.*mac.*Port.*.*2530.*" "c:\tnsnames.ora"') DO (
SET Var=%%a
)
IF "%Var: =%"=="(Host=mac)(Port=2530))" (
Copy %Var% zzzz
CHANGE zzzz "%Var%" "(Host=XXX)(Port=1500))"
)


This is my exact code.


Report •

#6
September 9, 2010 at 05:33:16
download sed for windows then do this

C:\test>more file
(Host =mac)(Port=2530))
(Host=mac) (Port=2530))
(Host=mac)(Port =2530))
(Host=mac)(Port= 2530))

C:\test>sed -r "s@(.*Host[ \t]*=[ \t]*)(.[^\)]*)(.*Port[ \t]*=[ \t]*)(.[^\)]*)@\1MXXX\32555@" file
(Host =MXXX)(Port=2555))
(Host=MXXX) (Port=2555))
(Host=MXXX)(Port =2555))
(Host=MXXX)(Port= 2555))


GNU win32 packages | Gawk


Report •

#7
September 9, 2010 at 14:19:30
Wow, my apologies. This should work:

@ECHO OFF

FOR /f "tokens=*" %%a IN ('FINDSTR ".*Host.*HXXX.*Port.*1500.*" "123.txt"') DO (
	SET Var=%%a
)
IF NOT "%Var: =%"=="(Host=HXXX)(Port=1500))" EXIT
COPY %Var% zzzz
CHANGE zzzz "%Var%" "(Host=XXX)(Port=1500))"

It assumes that (Host = HXXX)(Port = 1500)) is the only thing on the line.

Can I put a question here?


Report •

#8
September 9, 2010 at 17:15:58
@matt, OP is saying that he might have spaces. See the sample input file in my post #6. Those are scenarios of spaces he mentioned. So your batch should be able to take care of all those types of scenarios, not just one.

GNU win32 packages | Gawk


Report •

#9
September 9, 2010 at 18:21:02
@ghostdog, It will. as long as spaces are the only thing added.

It drops every space from the entry, and checks to see if it equals what it normally would be (without the spaces). Then he can replace it using change as he did in his original post.

If I've missed something and made a mistake, let me know haha. As for as I can tell it should work.

EDIT: Ohhh I see what you are saying, it won't keep the current spaces... Well, If he needs it too then your sed code is definitely the way to go.

His orignal codes that didn't work wouldn't have kept them either though. Guess we'll just have to see what one he decides to use.

Can I put a question here?


Report •

#10
September 10, 2010 at 00:11:09
Hi Matt /Ghostdog,
I appriciate your assistance,But it is not working for me.And I cant use SED also
I have to change TNS in tnsnames.ora file in many computers,so cant install it in every computer.

What i have to do is:- Change HOST and PORT in following text .This is one tns ,we have many tns in the file.

PMAP.com =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(Host=XXXX)(Port=1500))
)
(CONNECT_DATA =
(SID = PMAP)
)
)

to
PMAP.com =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(Host=YYYY)(Port=9900))
)
(CONNECT_DATA =
(SID = PMAP)
)
)

I used change .com but if we have space in (Host=XXXX)(Port=1500))
Change .com will not work.
Please help ,
thanks in advance.tested all above solutions.


Report •

#11
September 10, 2010 at 00:23:18
you only need to download sed once!! Its just a small exe file you can bring everywhere. No need to download at every computer.
So where did you get change.com ? You downloaded it also right?

GNU win32 packages | Gawk


Report •

#12
September 10, 2010 at 03:17:06
We are making this batch for the ease for sevrals users..I thisnk this is not good idea.

Do you have any other Solution.


Report •

#13
September 10, 2010 at 12:22:40
If you can get me a copy of change.com for a 64-bit machine I can try a few different things. At the moment I'm just shooting blindly.

However, sed is just a small exe, just like change is. It wouldn't be any bigger of a deal to stick on a usb drive and carry it with you. That's what you would have to do with change anyways.

Can I put a question here?


Report •

#14
September 12, 2010 at 22:53:25
Sure Plz give me your Email ID.I will send you ..

Report •

#15
September 13, 2010 at 13:47:27
Well, I for somereason can't get change to work. I've never used it before, so I don't know the syntaxes.

I am able to set "(Host=XXXX)(Port=1500)" or any variation to a variable. the only part not working is the change command that you supplied. ie, I done think that this is going to get done, you need to download sed. A program called Quick Batch File Converter will convert the batch file to an exe. You can compile sed with the batch file and hand it out as one exe.

The only downfall is that it's detected as a false positive by some anti-virus software.

Here's what I was able to get:

FOR /f "skip=3 tokens=2,3,4 delims=)" %%a IN (FileName.txt) DO (
	SET Var=%%a%%b
)
ECHO %Var%
PAUSE
IF "%Var: =%"=="(Host=HXXX)(Port=1500)" (
	Copy "%Var%" zzzz
	PAUSE
	CHANGE zzzz "%Var%" "(Host = MAAA)(Port = 2555)"
)
PAUSE

Can I put a question here?


Report •

Ask Question