Page 1 of 1

How to split a line in a text file that has no delimiters?

Posted: 17 Jul 2016 11:07
by SIMMS7400
Hi Team -

I need to read a certain line of a text file, and return the fourt column essentially. Unfortunately, I'm unable to assign any delimiters to this output file from one of our systems which is why is posing an issue for me.

Here is what the exact file looks like:

MAXL> login admin welcome1 on epmxxxx;

OK/INFO - 1051034 - Logging in user [admin@Native Directory].
OK/INFO - 1241001 - Logged in to Essbase.

MAXL> display variable GENJBAPP.Fin_Plan.Curr_Fcst;

application database variable value
+-------------------+-------------------+-------------------+-------------------
GENJBAPP Fin_Plan Curr_Fcst V7_7

MAXL> logout;

User admin is logged out



I need it to read the line in red and output the fourth string, which is V7_7.

This line will always start with GENJBAPP and be inclusive of 4 sections of strings.

Is this possible?

Thank you!

Re: How to read text file line with no delimiters?

Posted: 17 Jul 2016 11:37
by foxidrive
Does this give you the correct data?

Code: Select all

@echo off
for /f "tokens=4" %%a in ('findstr "^GENJBAPP" "c:\folder\file.txt" ') do set "variable=%%a"
echo "%variable%"
pause

Re: How to read text file line with no delimiters?

Posted: 17 Jul 2016 11:50
by SIMMS7400
HI Fox -

Thank you for the quick response!

Unfortunately, it's just displaying the following:

""


Thanks!

Re: How to read text file line with no delimiters?

Posted: 17 Jul 2016 12:10
by foxidrive
Is that the only text on the screen?

It works fine for me when I used your sample data.

Re: How to read text file line with no delimiters?

Posted: 17 Jul 2016 13:27
by Compo
My guess foxidrive is columns suggests that the line in red may begin with spaces and or tabs!
therefore

Code: Select all

for /f "tokens=4" %%a in ('findstr/r "^[\ \   ]*GENJBAPP" "test11.txt" ') do set "variable=%%a"
i.e. ^[\<space>\<tab>]*

Re: How to read text file line with no delimiters?

Posted: 17 Jul 2016 14:10
by Squashman
SIMMS7400 wrote:HI Fox -

Thank you for the quick response!

Unfortunately, it's just displaying the following:

""


Thanks!

Then you did not give an exact representation of your data.

Re: How to read text file line with no delimiters?

Posted: 17 Jul 2016 16:24
by SIMMS7400
Hi Guys -

Compo's solution worked like a charm!

Thank you very much to all!

Re: How to read text file line with no delimiters?

Posted: 18 Jul 2016 04:06
by foxidrive
That's the reason compo, but I read a clear statement that that wasn't the case.

SIMMS7400 wrote:This line will always start with GENJBAPP and be inclusive of 4 sections of strings.

The failure could have been an editing mistake in making the batch file too and after so many years of seeing 'finger-trouble' I seldom make assumptions.

SIMMS7400 may be learning how stupidly exact that batch scripting can be. :)

Squashman wrote:
SIMMS7400 wrote:HI Fox -
Unfortunately, it's just displaying the following:

""

Then you did not give an exact representation of your data.

I'm focusing more on trying to educate people about how to ask questions and why it's important to show real information.

It's better than arguing later and it still entertains me.... :)

Re: How to read text file line with no delimiters?

Posted: 18 Jul 2016 07:12
by Aacini
I would like to add that this title: "How to read text file line with no delimiters?" means to me that the line to read have no CR+LF delimiters, and that a clear question title also helps to better understand the question (beginning with the OP himself! :D ).

Antonio

Re: How to read text file line with no delimiters?

Posted: 18 Jul 2016 07:33
by Squashman
SIMMS7400 wrote:I need to read a certain line of a text file, and return the fourt column essentially. Unfortunately, I'm unable to assign any delimiters to this output file from one of our systems which is why is posing an issue for me.

If you happened to read the help for the FOR command.

Code: Select all

delims=xxx      - specifies a delimiter set.  This replaces the
                          default delimiter set of space and tab.

Re: How to read text file line with no delimiters?

Posted: 18 Jul 2016 11:37
by foxidrive
Aacini wrote:I would like to add that this title: "How to read text file line with no delimiters?" means to me that the line to read have no CR+LF delimiters, and that a clear question title also helps to better understand the question (beginning with the OP himself! :D ).

Antonio


I think you'd agree Antonio that the spaces are a delimiter and in this case SIMMS7400 isn't aware that spaces can be a delimiter.

Squashman has shown you the help SIMMS7400, and it shows the reason why I didn't use a delims= and compo similarly has not used delims=

Re: How to read text file line with no delimiters?

Posted: 18 Jul 2016 13:49
by Aacini
foxidrive wrote:
Aacini wrote:I would like to add that this title: "How to read text file line with no delimiters?" means to me that the line to read have no CR+LF delimiters, and that a clear question title also helps to better understand the question (beginning with the OP himself! :D ).

Antonio


I think you'd agree Antonio that the spaces are a delimiter and in this case SIMMS7400 isn't aware that spaces can be a delimiter.


Yes of course, but I want to note that the topic title refers TO READ a FILE LINE WITH NO DELIMITERS, that would be a problem for both "FOR /F" and "SET /P" methods to read lines.

However, the OP described an entirely different problem that is not related to READ A LINE, but to "SPLIT a file line with no delimiters".

I think that the simple fact to write the right title to a question means that the OP understand his own problem, so this behaviour should be encouraged...

Antonio

Re: How to read text file line with no delimiters?

Posted: 18 Jul 2016 17:51
by foxidrive
Aacini wrote:However, the OP described an entirely different problem that is not related to READ A LINE, but to "SPLIT a file line with no delimiters".

Antonio


You're absolutely right Antonio, and I didn't see what you were referring to earlier. I've edited the title of the thread as you suggested.