Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
SIMMS7400
- Posts: 546
- Joined: 07 Jan 2016 07:47
#1
Post
by SIMMS7400 » 17 Jul 2016 11:07
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!
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#2
Post
by foxidrive » 17 Jul 2016 11:37
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
-
SIMMS7400
- Posts: 546
- Joined: 07 Jan 2016 07:47
#3
Post
by SIMMS7400 » 17 Jul 2016 11:50
HI Fox -
Thank you for the quick response!
Unfortunately, it's just displaying the following:
""
Thanks!
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#4
Post
by foxidrive » 17 Jul 2016 12:10
Is that the only text on the screen?
It works fine for me when I used your sample data.
-
Compo
- Posts: 600
- Joined: 21 Mar 2014 08:50
#5
Post
by Compo » 17 Jul 2016 13:27
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>]*
-
Squashman
- Expert
- Posts: 4488
- Joined: 23 Dec 2011 13:59
#6
Post
by Squashman » 17 Jul 2016 14:10
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.
-
SIMMS7400
- Posts: 546
- Joined: 07 Jan 2016 07:47
#7
Post
by SIMMS7400 » 17 Jul 2016 16:24
Hi Guys -
Compo's solution worked like a charm!
Thank you very much to all!
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#8
Post
by foxidrive » 18 Jul 2016 04:06
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....

-
Aacini
- Expert
- Posts: 1932
- Joined: 06 Dec 2011 22:15
- Location: México City, México
-
Contact:
#9
Post
by Aacini » 18 Jul 2016 07:12
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!

).
Antonio
-
Squashman
- Expert
- Posts: 4488
- Joined: 23 Dec 2011 13:59
#10
Post
by Squashman » 18 Jul 2016 07:33
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.
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#11
Post
by foxidrive » 18 Jul 2016 11:37
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!

).
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=
-
Aacini
- Expert
- Posts: 1932
- Joined: 06 Dec 2011 22:15
- Location: México City, México
-
Contact:
#12
Post
by Aacini » 18 Jul 2016 13:49
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!

).
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
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#13
Post
by foxidrive » 18 Jul 2016 17:51
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.