Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Bash script to parse the Windows version written inside the license.rtf

Posted on 2010-09-17
21
Medium Priority
?
624 Views
Last Modified: 2013-12-26
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.
0
Comment
Question by:marietto2008
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 12
  • 9
21 Comments
 
LVL 14

Expert Comment

by:Dushyant Sharma
ID: 33700013
If it is in the third line always then you can use the script below
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
0
 
LVL 14

Expert Comment

by:Dushyant Sharma
ID: 33700023
An alternate can be

cat winver.txt | grep "WINDOWS"

but this will return all the lines containing WINDOWS (all caps)
0
 
LVL 2

Author Comment

by:marietto2008
ID: 33710714
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/sh$ 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/sh$

in this case I need to store inside a variable the output : WINDOWS 7 ULTIMATE
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:Dushyant Sharma
ID: 33711542
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
0
 
LVL 2

Author Comment

by:marietto2008
ID: 33711557
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.
0
 
LVL 2

Author Comment

by:marietto2008
ID: 33711559
errata corrige :

cat licence.rtf | grep "WINDOWS" returns * nothing that I can use as is *
0
 
LVL 14

Expert Comment

by:Dushyant Sharma
ID: 33711575
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.
0
 
LVL 2

Author Comment

by:marietto2008
ID: 33711675
mario@mario-desktop:/media/FREEDOS/sh$ cat license.rtf | grep "WINDOWS" | cut -d\ -f8

error : cut: delimiter must be a single character.
0
 
LVL 14

Expert Comment

by:Dushyant Sharma
ID: 33711692
use it in single quotes '\'
0
 
LVL 2

Author Comment

by:marietto2008
ID: 33711698
mario@mario-desktop:/media/FREEDOS/sh$ cat license.rtf | grep "WINDOWS" | cut -d'\' -f8

sb120
0
 
LVL 2

Author Comment

by:marietto2008
ID: 33711701
this is the beginning of the license.rtf file :

{\rtf1\ansi\ansicpg1252\deff0\deflang1033\deflangfe2052\deftab360{\fonttbl{\f0\fswiss\fprq2\fcharset 0 Tahoma;}}
{\*\generator Msftedit 5.41.21.2508;}\viewkind4\uc1\pard\nowidctlpar\sb120\sa120\b\f0\fs20 MICROSOFT SOFTWARE LICENSE TERMS\par
\pard\brdrb\brdrs\brdrw10\brsp20 \nowidctlpar\sb120\sa120 WINDOWS 7 ULTIMATE\par
\pard\nowidctlpar\sb120\sa120\b0 These license terms are an agreement between Microsoft Corporation (or based on where you live, one of its affiliates) and $
\pard\nowidctlpar\sb120\sa120\tx0\'b7\tab updates,\par
\'b7\tab supplements,\par
\'b7\tab Internet-based services, and\par
\'b7\tab support services\par
\pard\nowidctlpar\sb120\sa120 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\sa120\tx360 1.\tab OVERVIEW.\par
0
 
LVL 14

Expert Comment

by:Dushyant Sharma
ID: 33711702
use -f9 or -f10 or may be -f7.. here number after f represents the column you want.
0
 
LVL 2

Author Comment

by:marietto2008
ID: 33711708
mario@mario-desktop:/media/FREEDOS/sh$ cat license.rtf | grep "WINDOWS" | cut -d'\' -f9

sa120 WINDOWS 7 ULTIMATE

mario@mario-desktop:/media/FREEDOS/sh$ cat license.rtf | grep "WINDOWS" | cut -d'\' -f10

par

the first should be good,but I have to cut "sa120"
0
 
LVL 14

Expert Comment

by:Dushyant Sharma
ID: 33711709
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
0
 
LVL 2

Author Comment

by:marietto2008
ID: 33711715
mario@mario-desktop:/media/FREEDOS/sh$ cat license.rtf | grep "WINDOWS" | cut -d'\' -f9 | cut -d' ' -f2
WINDOWS

has been cut exactly what I want : "7 ULTIMATE"
0
 
LVL 14

Accepted Solution

by:
Dushyant Sharma earned 2000 total points
ID: 33711747
i surely forgot  the another spaces :).. my bad.. well cut here will give you all the words separated by a space. But i believe you need all the things after sb120 so you can specify all the fields as

cut -d' ' -f "2 3 4"

0
 
LVL 2

Author Comment

by:marietto2008
ID: 33711768
Bingo,you "won" 500 points :D

mario@mario-desktop:/media/FREEDOS/sh$ 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.
0
 
LVL 2

Author Comment

by:marietto2008
ID: 33711770
*I hate*
0
 
LVL 2

Author Comment

by:marietto2008
ID: 33712315
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 ?
0
 
LVL 14

Expert Comment

by:Dushyant Sharma
ID: 33713927
Try this
if [ $ver_windows -eq "Microsoft Windows XP Home Edition" ]
then
    ver_windows_min="xp"
    echo $home
fi
0
 
LVL 2

Author Comment

by:marietto2008
ID: 33714182
FIXED : there was a stupid hidden space at the end of the first line.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Six Sigma Control Plans

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question