473,396 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Parse text file

Hi.. I'm a perl noob need to know how to write a script to parse a
file containing one to four of the following blocks of text? I then
want to print the results in a format showing the memory size (128)
for each device that was found?

Structure: Memory Device (Type 17)
Type: 17
Length: 15h
Handle: 0024h (36t)
Memory Array Handle: 0021
Memory Error Information Handle: FFFE
Total Width: 64 (0040h)
Data Width: 64 (0040h)
Size: 128 (0080h)
Form Factor: DIMM
Device Set: 0001h
Device Locator: DIMM 0
Bank Locator: BANK 0
Memory Type: SDRAM
Type Detail: 0080h
Serial Number:

For example, say the SMBIOS dump contained 2 of the above blocks and I
want to print something like:

myhost 128 256 x x

Would I use an array to store the 4 memory values? I tried something
like the following.. .Am I on the right track? I just need help
with how to parse the file and extract the memory sizes into some type
of variable.

while (<INFILE>)
{
if(/\(Type 17\)/)
{
while(<INFILE>)
{ if(/Size/)
{ # Assign size to array
$memory=~s/^\s*Size\:\s*//;
}
if(/Serial/)
{ next; }
}

}
}

.................................................. ...............
Posted via TITANnews - Uncensored Newsgroups Access
at http://www.TitanNews.com <<<<

-=Every Newsgroup - Anonymous, UNCENSORED, BROADBAND Downloads=-

Jul 19 '05 #1
2 12058
Your message will reach more people in comp.lang.perl.misc or
perl.beginners. This newsgroup is no longer a valid public newsgroup.

Tyaan <as**@asdf.com> wrote in message news:<95********************************@4ax.com>. ..
Would I use an array to store the 4 memory values?
Probably. Is the size the only thing you want to keep?

my @sizes = ();
while (<INFILE>) {
push(@sizes, $') if /^\s*Size\:\s*/;
}
print join("\t", @sizes), "\n";
while (<INFILE>)
{
if(/\(Type 17\)/)
{
while(<INFILE>)


This is definitely the wrong track. You don't want to have multiple
nested while()s reading from the same file handle.
Jul 19 '05 #2
On 20 Nov 2003 11:54:27 -0800, rj******@shell.com (Roy Johnson) wrote:
Your message will reach more people in comp.lang.perl.misc or
perl.beginners. This newsgroup is no longer a valid public newsgroup.

Tyaan <as**@asdf.com> wrote in message news:<95********************************@4ax.com>. ..
Would I use an array to store the 4 memory values?


Probably. Is the size the only thing you want to keep?

my @sizes = ();
while (<INFILE>) {
push(@sizes, $') if /^\s*Size\:\s*/;
}
print join("\t", @sizes), "\n";
while (<INFILE>)
{
if(/\(Type 17\)/)
{
while(<INFILE>)


This is definitely the wrong track. You don't want to have multiple
nested while()s reading from the same file handle.


I re-wrote it like this. Is this a more "proper" way of doing it?

open(INFILE, "smbios.txt");
read(INFILE, $_, -s "smbios.txt");
close(INFILE)
while (/(\(Type\s*\d*\))(.*?)(Structure)/s)
{
# Save strings
$temp=$';
$type=$1;
$value=$2;

# If a memory block is found, parse it.
if($type =~ /Type 17\)/)
{
$value=~/(.*?)(Size:)(\s*)(\d*)/s;
$memcount++;
@memory[$memcount]=$4;
}

$_=$temp;
}

.................................................. ...............
Posted via TITANnews - Uncensored Newsgroups Access
at http://www.TitanNews.com <<<<

-=Every Newsgroup - Anonymous, UNCENSORED, BROADBAND Downloads=-

Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: chuck amadi | last post by:
Hi , Im trying to parse a specific users mailbox (testwwws) and output the body of the messages to a file ,that file will then be loaded into a PostGresql DB at some point . I have read the...
23
by: Charles Law | last post by:
Does anyone have a regex pattern to parse HTML from a stream? I have a well structured file, where each line is of the form <sometag someattribute='attr'>text</sometag> for example <SPAN...
22
by: Ram Laxman | last post by:
Hi all, I have a text file which have data in CSV format. "empno","phonenumber","wardnumber" 12345,2234353,1000202 12326,2243653,1000098 Iam a beginner of C/C++ programming. I don't know how to...
6
by: nate | last post by:
Hello, Does anyone know where I can find an ASP server side script written in JavaScript to parse text fields from a form method='POST' using enctype='multipart/form-data'? I'd also like it to...
5
by: liming | last post by:
Hi all, I have to parse two text files on a weekly basis. Each range from 300kb to 1mb in total. Each text file has 5 columns (name,id, dollar, startdate,enddate), everytime, a) I need to...
13
by: DH | last post by:
Hi, I'm trying to strip the html and other useless junk from a html page.. Id like to create something like an automated text editor, where it takes the keywords from a txt file and removes them...
1
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C programming. FYI Although I have called this...
0
by: ghostface | last post by:
**How do I parse a textfile and edit only a certain part of it. Specifically, just the last column. My textfile looks like this. #Server Group 1...
6
by: =?Utf-8?B?RGF2aWRN?= | last post by:
Hello, I have an XML file generated from a third party application that I would like to parse. Ideally, I plan on having a windows service setup to scan various folders for XML files and parse the...
11
by: JRough | last post by:
I'm trying to use output buffering to cheat so i can print to excel which is called later than this header(). header("Content-type: application/xmsdownload"); header("Content-Disposition:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.