Mario Zio
asked on
Bash script to parse the Windows version written inside the license.rtf
Hello,
Since I'm totally newbie in bash scripting,can someone help me to write a bash script to parse the version of Windows written inside the license.rtf file ? Thanks.
If it starts with :
MICROSOFT SOFTWARE LICENSE TERMS
WINDOWS 7 ULTIMATE
These license terms are an agreement between Microsoft Corporation (or based on where you live, one of its affiliates) and you. Please read them. They apply to the software named above, which includes the media on which you received it, if any. Printed-paper license terms, which may come with the software, may replace or modify any on-screen license terms. The terms also apply to any Microsoft
I need to grab the version of Windows used,in this case it is : WINDOWS 7 ULTIMATE
thanks in advance.
Since I'm totally newbie in bash scripting,can someone help me to write a bash script to parse the version of Windows written inside the license.rtf file ? Thanks.
If it starts with :
MICROSOFT SOFTWARE LICENSE TERMS
WINDOWS 7 ULTIMATE
These license terms are an agreement between Microsoft Corporation (or based on where you live, one of its affiliates) and you. Please read them. They apply to the software named above, which includes the media on which you received it, if any. Printed-paper license terms, which may come with the software, may replace or modify any on-screen license terms. The terms also apply to any Microsoft
I need to grab the version of Windows used,in this case it is : WINDOWS 7 ULTIMATE
thanks in advance.
An alternate can be
cat winver.txt | grep "WINDOWS"
but this will return all the lines containing WINDOWS (all caps)
cat winver.txt | grep "WINDOWS"
but this will return all the lines containing WINDOWS (all caps)
ASKER
I like the option n.2. I've tried to parse the eula.txt of windows XP with this command :
mario@mario-desktop:/media /FREEDOS/s h$ cat eula.txt | grep "Microsoft Windows"
Microsoft Windows XP Home Edition
I need to store the output "Microsoft Windows XP Home Edition" inside a variable
and I've tried to parse the license.rtf of Windows Vista / Seven with this command :
cat license.rtf | grep "WINDOWS"
\pard\brdrb\brdrs\brdrw10\ brsp20 \nowidctlpar\sb120\sa120 WINDOWS 7 ULTIMATE\par
mario@mario-desktop:/media /FREEDOS/s h$
in this case I need to store inside a variable the output : WINDOWS 7 ULTIMATE
mario@mario-desktop:/media
Microsoft Windows XP Home Edition
I need to store the output "Microsoft Windows XP Home Edition" inside a variable
and I've tried to parse the license.rtf of Windows Vista / Seven with this command :
cat license.rtf | grep "WINDOWS"
\pard\brdrb\brdrs\brdrw10\
mario@mario-desktop:/media
in this case I need to store inside a variable the output : WINDOWS 7 ULTIMATE
inside a script you can always store output into a variable using the command in `` (acutes)
temp = `cat licence.rtf | grep "WINDOWS"`
echo $temp
this should store the the value of the commands (in your case "WINDOWS 7 ULTIMATE") to the variable temp
temp = `cat licence.rtf | grep "WINDOWS"`
echo $temp
this should store the the value of the commands (in your case "WINDOWS 7 ULTIMATE") to the variable temp
ASKER
cat licence.rtf | grep "WINDOWS" returns nothing,because Rich text is a kind of markup language, similar to html. What you see in the display is not exactly the text the file itself contains. The parsing would have to take this into account.
ASKER
errata corrige :
cat licence.rtf | grep "WINDOWS" returns * nothing that I can use as is *
cat licence.rtf | grep "WINDOWS" returns * nothing that I can use as is *
ah sure... then may be you can use cut to get the output. Do not have a linux box right now to test it but you can do something like below
cat licence.rtf | grep "WINDOWS" | cut -d\ -f8
here -d\ is used for delimiter as "\"
-f8 is for field 8 after cut is performed, so this should return the output.
you can also use awk for this.
cat licence.rtf | grep "WINDOWS" | cut -d\ -f8
here -d\ is used for delimiter as "\"
-f8 is for field 8 after cut is performed, so this should return the output.
you can also use awk for this.
ASKER
mario@mario-desktop:/media /FREEDOS/s h$ cat license.rtf | grep "WINDOWS" | cut -d\ -f8
error : cut: delimiter must be a single character.
error : cut: delimiter must be a single character.
use it in single quotes '\'
ASKER
mario@mario-desktop:/media /FREEDOS/s h$ cat license.rtf | grep "WINDOWS" | cut -d'\' -f8
sb120
sb120
ASKER
this is the beginning of the license.rtf file :
{\rtf1\ansi\ansicpg1252\de ff0\deflan g1033\defl angfe2052\ deftab360{ \fonttbl{\ f0\fswiss\ fprq2\fcha rset 0 Tahoma;}}
{\*\generator Msftedit 5.41.21.2508;}\viewkind4\u c1\pard\no widctlpar\ sb120\sa12 0\b\f0\fs2 0 MICROSOFT SOFTWARE LICENSE TERMS\par
\pard\brdrb\brdrs\brdrw10\ brsp20 \nowidctlpar\sb120\sa120 WINDOWS 7 ULTIMATE\par
\pard\nowidctlpar\sb120\sa 120\b0 These license terms are an agreement between Microsoft Corporation (or based on where you live, one of its affiliates) and $
\pard\nowidctlpar\sb120\sa 120\tx0\'b 7\tab updates,\par
\'b7\tab supplements,\par
\'b7\tab Internet-based services, and\par
\'b7\tab support services\par
\pard\nowidctlpar\sb120\sa 120 for this software, unless other terms accompany those items. If so, those terms apply.\par
\b By using the software, you accept these terms. If you do not accept them, do not use the software. Instead, return it to the retailer for a refund or cre$
\b As described below, using the software also operates as your consent to the transmission of certain computer information during activation, validation an$
\pard\brdrt\brdrs\brdrw10\ brsp20 \nowidctlpar\sb120\sa120 If you comply with these license terms, you have the rights below for each license you acquire.\par
\pard\nowidctlpar\sb120\sa 120\tx360 1.\tab OVERVIEW.\par
{\rtf1\ansi\ansicpg1252\de
{\*\generator Msftedit 5.41.21.2508;}\viewkind4\u
\pard\brdrb\brdrs\brdrw10\
\pard\nowidctlpar\sb120\sa
\pard\nowidctlpar\sb120\sa
\'b7\tab supplements,\par
\'b7\tab Internet-based services, and\par
\'b7\tab support services\par
\pard\nowidctlpar\sb120\sa
\b By using the software, you accept these terms. If you do not accept them, do not use the software. Instead, return it to the retailer for a refund or cre$
\b As described below, using the software also operates as your consent to the transmission of certain computer information during activation, validation an$
\pard\brdrt\brdrs\brdrw10\
\pard\nowidctlpar\sb120\sa
use -f9 or -f10 or may be -f7.. here number after f represents the column you want.
ASKER
mario@mario-desktop:/media /FREEDOS/s h$ cat license.rtf | grep "WINDOWS" | cut -d'\' -f9
sa120 WINDOWS 7 ULTIMATE
mario@mario-desktop:/media /FREEDOS/s h$ cat license.rtf | grep "WINDOWS" | cut -d'\' -f10
par
the first should be good,but I have to cut "sa120"
sa120 WINDOWS 7 ULTIMATE
mario@mario-desktop:/media
par
the first should be good,but I have to cut "sa120"
i can also see a space "sa120 WINDOWS 7 ULTIMATE" so you need to do another cut after getting this string like
cat license.rtf | grep "WINDOWS" | cut -d'\' -f9 | cut -d' ' -f2
here ' ' is space
cat license.rtf | grep "WINDOWS" | cut -d'\' -f9 | cut -d' ' -f2
here ' ' is space
ASKER
mario@mario-desktop:/media /FREEDOS/s h$ cat license.rtf | grep "WINDOWS" | cut -d'\' -f9 | cut -d' ' -f2
WINDOWS
has been cut exactly what I want : "7 ULTIMATE"
WINDOWS
has been cut exactly what I want : "7 ULTIMATE"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Bingo,you "won" 500 points :D
mario@mario-desktop:/media /FREEDOS/s h$ cat license.rtf | grep "WINDOWS" | cut -d'\' -f9 | cut -d' ' -f "2 3 4"
WINDOWS 7 ULTIMATE
btw sh scripting is a kind of language I have because you have to pay your attention over aspects frankly not so important and you can't pay attention over the whole piece of code.
mario@mario-desktop:/media
WINDOWS 7 ULTIMATE
btw sh scripting is a kind of language I have because you have to pay your attention over aspects frankly not so important and you can't pay attention over the whole piece of code.
ASKER
*I hate*
ASKER
ver_windows=$(cat /mnt/sda1/Windows/system32 /eula.txt | grep "Microsoft Windows")
echo $ver_windows
Microsoft Windows XP Home Edition
if [ "$ver_windows" = "Microsoft Windows XP Home Edition" ]; then ver_windows_min="xp"
echo home
fi
output : nothing
I think that $ver_windows is not = to "Microsoft Windows XP Home Edition" ,why ?
echo $ver_windows
Microsoft Windows XP Home Edition
if [ "$ver_windows" = "Microsoft Windows XP Home Edition" ]; then ver_windows_min="xp"
echo home
fi
output : nothing
I think that $ver_windows is not = to "Microsoft Windows XP Home Edition" ,why ?
Try this
if [ $ver_windows -eq "Microsoft Windows XP Home Edition" ]
then
ver_windows_min="xp"
echo $home
fi
if [ $ver_windows -eq "Microsoft Windows XP Home Edition" ]
then
ver_windows_min="xp"
echo $home
fi
ASKER
FIXED : there was a stupid hidden space at the end of the first line.
i=0
while read line
do
if [ $i -eq 3 ]
then
echo "$line"
fi
i=`expr $i + 1`
done < winver.txt
here winver.txt is the file to read