Extract a portion of a command line output

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
komathi
Posts: 14
Joined: 18 May 2014 04:48

Extract a portion of a command line output

#1 Post by komathi » 13 Jun 2014 05:00

Hi,,

For encrypting password in a data loader i'm using the following code

Code: Select all

java -cp ../lib/EnhencedDataloader.jar com.salesforce.dataloader.security.EncryptionUtil -g "seeddata" > %rootpath%bin\Key.txt
 

and writing the output in the key.txt file. as below,
2014-06-13 16:23:02,859 INFO [main] security.EncryptionUtil main (EncryptionUtil.java:304) - 99b7041393bd3e82

but i need only the value 99b7041393bd3e82 to use in next setp.

How to remove this unwanted text,
In my old version i wont get this extra line in the key.txt file

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Alter the command line output text

#2 Post by Squashman » 13 Jun 2014 06:05

put the command into a FOR /F command and use a hyphen as a delimiter.
for /f "tokens=4 delims=-" %%G in ('java command here') do echo %%G>file.txt

komathi
Posts: 14
Joined: 18 May 2014 04:48

Re: Alter the command line output text

#3 Post by komathi » 13 Jun 2014 08:19

hi Squashman ,

Thank u , have a single space in front , how to remove this?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Alter the command line output text

#4 Post by foxidrive » 13 Jun 2014 08:38

Your string might always be 16 characters - but you haven't given much detail.

If so you can take the last 16 characters from the line.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Alter the command line output text

#5 Post by Squashman » 13 Jun 2014 08:51

Well if your output is always formatted that way then use a space as the delimiter and if my counting is correct it should be the 8th token then.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Alter the command line output text

#6 Post by foxidrive » 13 Jun 2014 09:02

Squashman wrote:Well if your output is always formatted that way then use a space as the delimiter and if my counting is correct it should be the 8th token then.


+1 That's also a good solution, given a predictable output format

with the hyphen I think it's the 9th token.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Alter the command line output text

#7 Post by Squashman » 13 Jun 2014 09:05

foxidrive wrote:
Squashman wrote:Well if your output is always formatted that way then use a space as the delimiter and if my counting is correct it should be the 8th token then.


+1 That's also a good solution, given a predictable output format.

Lets hope my Crystal Ball is working correctly today.

komathi
Posts: 14
Joined: 18 May 2014 04:48

Re: Alter the command line output text

#8 Post by komathi » 13 Jun 2014 10:51

Thanks all,

for /f "tokens=9 delims= " %%G in ('java -cp ../lib/EnhencedDataloader.jar com.salesforce.dataloader.security.EncryptionUtil -g "seeddata"') do echo %%G>%rootpath%bin\Key.txt


it works for me.

:)

Post Reply