Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 678
  • Last Modified:

Reading a text fiile

Hi guys, hope you are all good and can assist.

Guys,

We are using an Enterprise build with 10 or so language packs installed.
The user has the option at the start of the build to choose their language.

What we need to do is to trap what language they selected.
This is the Default system UI language.

In the case of that language being English, then the Default system UI language is en-US.

We can grab this by:

dism /online /get-intl > test.txt

The output of test.txt is in the code snippet below.

I have tried different language selections, and the value for  Default system UI language appears to be always on Line 9 in the text file.

So my question is.

Is there a way to read the test.txt file, and read a certain line number, in this case, line 9, and trap the value of Default system UI language into a variable?

I cannot do the folowing:

dism /Online /Get-Intl | find "Default system UI language"

This would work if the language chosen was English, but if the language chosen was Chinese for example, then

dism /Online /Get-Intl ^| find "Default system UI language"

would fail to find "Default system UI language" since the text is in Chinese.

Which is why I want to read line number 9, and find the value after the colon.

line9 (english) Default system UI language : en-US
line9 (german) <in german.....>: de-DE

So, something like,

1) read text file
2) read line number 9

if de-DE, then we know its German
if en-US, then we know its English
if es-ES, then we know its Spain
if fr-FR, then we know its France
if it-IT, then we know its Italy
if ja-JP, then we know its Japanese
if nb-NO, then we know its Norway
if pl-PL, then we know its Poland
if pt-BR, then we know its Brasil
if ru-RU, then we know its Russian
if zh-CN, then we know its Simplified Chinese
if zh-HK, then we know its Traditional Chinese

Any help greatly appreciated.
Deployment Image Servicing and Management tool
Version: 6.1.7600.16385

Image Version: 6.1.7600.16385


Reporting online international settings.

Default system UI language : en-US

Open in new window

0
Simon336697
Asked:
Simon336697
4 Solutions
 
lexlythiusCommented:
If you can use Windows Script Host's JScript, you're done.
Read the file, match with a RegExp and be happy.
Or is it not an option?
0
 
rfportillaCommented:
download grep for windows: http://gnuwin32.sourceforge.net/packages/grep.htm

I created a text file called temp.txt with your data in it.  The result of the following command:

grep "Default system UI language :" deleteme.txt

is
Default system UI language : en-US

0
 
lexlythiusCommented:
0
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 
lexlythiusCommented:
Good ol' grep.
Next question would be how to isolate the sixth element after splitting the line using the space as delimiter.
0
 
rfportillaCommented:
Ok, download sed also: http://gnuwin32.sourceforge.net/packages/sed.htm

grep "Default system UI language : \(.*\)" deleteme.txt | sed "s/Default system UI language : \(.*\)$/\1/"

yields: en-US

And I used deleteme.txt instead of temp.txt
0
 
lexlythiusCommented:
You should also get GAwk for Windows to isolate the result. So you would go like this:
C:\> grep "Default system UI language :" deleteme.txt | gawk -F": " "{ print $2 }"
en-US

Open in new window

0
 
lexlythiusCommented:
@rfportilla beat me to post ;-).

Use sed or gawk, but not both.
0
 
rfportillaCommented:
Sorry, @lexlythius.  You snooze, you lose.  ;-)
0
 
Simon336697Author Commented:
Guys thanks so much for your help.

The following works, but I get 1 space before "en-US". Is there any way to get rid of this?

for /f "tokens=1* delims=:" %a in ('dism /online /get-intl ^| find /N "en-US" ^| find "[9]"') do @echo %b
 en-US

0
 
rfportillaCommented:
When you do it this way, you have to specify what you are looking for.  What if the language is not en-US?  The methods we were giving above don't require you to know the language.  If you need to use the command to produce this, you can use

dism /online /get-intl | grep "Default system UI language : \(.*\)" | sed "s/Default system UI language : \(.*\)$/\1/"

0
 
rfportillaCommented:
Ok, this is the last response you're getting from me:

for /f "tokens=5* delims= " %a in ('dism /online /get-intl  ^| find /N "Default" ^| find "[9]"') do @echo %b

0
 
rfportillaCommented:
Actually should be:

for /f "tokens=5* delims= " %a in ('type deleteme.txt ^| find /N "Default system UI language : " ^| find "[9]"') do @echo %b

Just to be on the safe side.
0
 
rfportillaCommented:
Ok, really, the last post.  Drop the find [9], just in case the output is changed and it no longer appears on the 9th line, this will work anyway:

for /f "tokens=5* delims= " %a in ('dism /online /get-intl ^| find /N "Default system UI language : "') do @echo %b
0
 
canaliCommented:
for /f "tokens=6" %a in ('dism /online /get-intl ^| find /I "Default system UI language : "') do @echo %a
0
 
oBdACommented:
The comments so far were always looking for the term "Default system UI language" which, according to your description, will fail on an installation with a non-"en-US" UI language:
line9 (english) Default system UI language : en-US
line9 (german) <in german.....>: de-DE


So here's a (currently rather verbose script for potential debugging) that will check for expected languages in given lines. it will exit with errorlevel 1 if the language couldn't be determined, 0 otherwise.
@echo off
setlocal
REM *** space separated list of expected UI language tokens:
set ExpectedLanguages=de-DE en-US es-ES fr-FR it-IT ja-JP nb-NO pl-PL pt-BR ru-RU zh-CN zh-HK
REM *** space separated list of of line numbers in which to expect the language token:
set ExpectedLines=9
set SystemUILanguage=
for /f "tokens=1,2* delims=:" %%a in ('dism /online /get-intl ^| findstr /i /n "%ExpectedLanguages%"') do (
  echo Found language token in line %%a ^(%%b:%%c^).
  for %%l in (%ExpectedLines%) do (
    if "%%a"=="%%l" set SystemUILanguage=%%c
  )
)
if "%SystemUILanguage%"=="" (
  echo Unexpected language, or output in unexpected line of "dism.exe".
  echo Expected languages:
  echo %ExpectedLanguages%
  echo Language expected in line^(s^):
  echo %ExpectedLines%
  exit /b 1
)
set SystemUILanguage=%SystemUILanguage: =%
echo System UI language found: %SystemUILanguage%

Open in new window

0
 
rfportillaCommented:
Has this been resolved?  I think we have several viable answers here.  Please inform.  Thx.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now