Page 1 of 1

search string

Posted: 10 Feb 2015 15:58
by joecepy
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

Re: search string

Posted: 10 Feb 2015 17:11
by Yury
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=*))
.

Re: search string

Posted: 10 Feb 2015 19:59
by joecepy
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.

Re: search string

Posted: 10 Feb 2015 20:42
by joecepy

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?

Re: search string

Posted: 10 Feb 2015 21:11
by Squashman
What the heck are you trying to do with this?

Code: Select all

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

Re: search string

Posted: 10 Feb 2015 21:20
by joecepy
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=*
  )
)

Re: search string

Posted: 11 Feb 2015 00:19
by Yury
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=*
 )
 )
)


.