search string

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
joecepy
Posts: 27
Joined: 28 Sep 2012 13:58

search string

#1 Post by joecepy » 10 Feb 2015 15:58

I have following file that contains following text...

Code: Select all

11072   [646]   INFO   2015-02-10 14:31:58.759   Dependency   Adding cube: Cube 'DETAIL1' depends on cube 'INFO_BLAH1'.
11072   [646]   INFO   2015-02-10 14:31:58.759   Dependency   Adding cube: Cube 'DETAIL' depends on cube 'INFO_BLAH'.
9764   [62f]   INFO   2015-02-10 14:33:27.491   Dependency   Adding cube: Cube 'DETAIL1' depends on cube 'INO_BLAH1'.
9764   [62f]   INFO   2015-02-10 14:33:27.491   Dependency   Adding cube: Cube 'DETAIL' depends on cube 'INFO_BLAH'.


The output should in

Code: Select all

Cube: DETAIL1 on INFO_BLAH1
Cube: DETAIL on INFO_BLAH


so I basically need to search for string of text that is in between the character ' ' for each line (so there are 2 in each line) and remove the duplicates. Any directions how I can go about this? purely batch. No third party applications in windows environment.

thanks

Yury
Posts: 115
Joined: 28 Dec 2013 07:54

Re: search string

#2 Post by Yury » 10 Feb 2015 17:11

joecepy wrote:9764 [62f] INFO 2015-02-10 14:33:27.491 Dependency Adding cube: Cube 'DETAIL1' depends on cube 'INO_BLAH1'.

I believe that the
9764 [62f] INFO 2015-02-10 14:33:27.491 Dependency Adding cube: Cube 'DETAIL1' depends on cube 'INFO_BLAH1'.
would be correct.


The code:

Code: Select all

@<"in.txt">"out.txt" (for /f "tokens=2,4 delims='" %%i in ('more') do @if not defined %%i_%%j (echo Cube: %%i on %%j& set %%i_%%j=*))
.

joecepy
Posts: 27
Joined: 28 Sep 2012 13:58

Re: search string

#3 Post by joecepy » 10 Feb 2015 19:59

The code:

Code: Select all

@<"in.txt">"out.txt" (for /f "tokens=2,4 delims='" %%i in ('more') do @if not defined %%i_%%j (echo Cube: %%i on %%j& set %%i_%%j=*))
.[/quote]

it works but I don't understand why it works...I tried changing the echo part and then it doesn't work anymore. I wanted to change it to FunctionName( %%i, %%j ); as an output but then it breaks.

joecepy
Posts: 27
Joined: 28 Sep 2012 13:58

Re: search string

#4 Post by joecepy » 10 Feb 2015 20:42

Code: Select all


@<"in.txt">"out.txt" (
for /f "tokens=2,4 delims='" %%i in ('more') do @if not defined %%i_%%j ( echo AddCubeDependency('%%i', '%%j&'^)^; set %%i_%%j=*))


why is code above not working?

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

Re: search string

#5 Post by Squashman » 10 Feb 2015 21:11

What the heck are you trying to do with this?

Code: Select all

( echo AddCubeDependency('%%i', '%%j&'^)^; set %%i_%%j=*))

joecepy
Posts: 27
Joined: 28 Sep 2012 13:58

Re: search string

#6 Post by joecepy » 10 Feb 2015 21:20

Squashman wrote:What the heck are you trying to do with this?

Code: Select all

( echo AddCubeDependency('%%i', '%%j&'^)^; set %%i_%%j=*))

I was trying to take Yuri's code and change it up little but it's driving me crazy.
I just want to echo out the text little bit.

I changed it a little for readability but it's gets worse and worse

Code: Select all

@echo off
@<"in.txt">"out.txt"
(
for /f "tokens=2,4 delims='" %%i in ('more') do
  @if not defined %%i_%%j
  (
   echo AddCubeDependency('%%i', '%%j'^)^;
   set %%i_%%j=*
  )
)

Yury
Posts: 115
Joined: 28 Dec 2013 07:54

Re: search string

#7 Post by Yury » 11 Feb 2015 00:19

joecepy, the correct code is

Code: Select all

@<"in.txt">"out.txt" (
for /f "tokens=2,4 delims='" %%i in ('more') do @(
 if not defined %%i_%%j (
  echo AddCubeDependency('%%i', '%%j'^);
  set %%i_%%j=*
 )
 )
)


.

Post Reply