Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Fri 19 Sep 2014, 14:00
All times are UTC - 4
 Forum index » Advanced Topics » Cutting edge
Help needed getting ramdisk_size using AWK (or sed) (SOLVED)
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 2 [17 Posts]   Goto page: 1, 2 Next
Author Message
pakt


Joined: 04 Jun 2005
Posts: 1089
Location: Sweden

PostPosted: Sun 30 Oct 2005, 05:08    Post subject:  Help needed getting ramdisk_size using AWK (or sed) (SOLVED)  

I'm working on an update to WakePup 1.0 that will also boot non-standard Puppies (Chubby, Murga, PizzaPup, etc) that use the ramdisk_size=xxxxx parameter when booting.

Some help is needed in extracting ramdisk_size=xxxxx from either isolinux.cfg (on CD) or syslinux.cfg (on USB flash drive).

The tools I have at hand are AWK & sed for DOS.

Here are extracts showing the relevant lines in the files:

(From puppy-1.0.5-mozilla-128Mb-Murga's isolinux.cfg)

Code:
default 1
DISPLAY BOOT.MSG
prompt 1
label 1
 kernel vmlinuz
 append root=/dev/ram0 initrd=image.gz ramdisk_size=63488 PFILE=pup001-none-262144
<--snip-->


(And from a modified puppy-1.0.5-mozilla-128Mb-Murga USB syslinux.cfg)

Code:
default vmlinuz root=/dev/ram0 initrd=image.gz
append ramdisk_size=63488 PSLEEP=25 PHOME=sda1 PFILE=pup100-none-262144 PKEYS=uk


What I have succeded in doing so far is to extract ramdisk_size=63488 like this (remember, I'm using AWK for DOS punctuation (" instead of '):

Code:
M:\awk "/ramdisk_size/{print \"set rdsize=\" $2;exit;}" %pupdrv%\syslinux.cfg >M:\tmp_.bat
call M:\tmp_.bat
del M:\tmp_.bat >NUL


This will set the FreeDOS environment variable rdsize=ramdisk_size=63488 and WakePup can then successfully boot into Puppy using this. Note that this only works when the variable is found in field #2. That's where the potential problem lies: the boot parameters can be written in a different order - ramdisk_size doesn't have to be in field #2, someone might place it at the end of the parameter line...

So here's the question: can anyone with a better knowledge of AWK syntax than me (that's just about anyone Wink) show me how to extract 'ramdisk_size=XXXXX' regardless of which field it is in?

Thanks in advance for any help Smile

Paul

Last edited by pakt on Mon 31 Oct 2005, 06:41; edited 1 time in total
Back to top
View user's profile Send private message 
rarsa


Joined: 29 May 2005
Posts: 3053
Location: Kitchener, Ontario, Canada

PostPosted: Sun 30 Oct 2005, 12:04    Post subject:  

Can there be spaces around the '=' ?

e.g.
Code:
append root =/dev/ram0 initrd= image.gz ramdisk_size = 63488 PFILE = pup001-none-262144
Back to top
View user's profile Send private message Visit poster's website 
rarsa


Joined: 29 May 2005
Posts: 3053
Location: Kitchener, Ontario, Canada

PostPosted: Sun 30 Oct 2005, 12:20    Post subject:  

I know that you said that you only had access to awk and sed. but... do you have access to grep?

Code:
grep -o 'ramdisk_size[ ]*=[ ]*[0-9]*'  %pupdrv%/syslinux.cfg


This gives you exactly what you are asking for. In any event, That's the regular expression you want to use to find the ramdisk_size even if you are not using grep.
Back to top
View user's profile Send private message Visit poster's website 
rarsa


Joined: 29 May 2005
Posts: 3053
Location: Kitchener, Ontario, Canada

PostPosted: Sun 30 Oct 2005, 12:51    Post subject:  

With awk there are different ways of doing it as it is a rich language.

Here is a one liner that does what you want:

Code:
awk '{ if(match($0,"ramdisk_size[ ]*=[ ]*[0-9]*")) printf(substr($0,RSTART,RLENGTH))}'  %pupdrv%/syslinux.cfg


That will handle spaces around the = sign and will return the ramdisk_size=63488 without a newline at the end.

I'm also a novice in awk (I've just written two awk commands in my life... this being the second one) but I've found some good resources like this tutorial http://www.grymoire.com/Unix/Awk.html#uh-47
Back to top
View user's profile Send private message Visit poster's website 
pakt


Joined: 04 Jun 2005
Posts: 1089
Location: Sweden

PostPosted: Sun 30 Oct 2005, 15:03    Post subject:  

rarsa, thanks for your responses.

rarsa wrote:
With awk there are different ways of doing it as it is a rich language.

Yes, it certainly seems to be a cryptic but powerful language. I've searched high and low on the internet and found ways of doing just about anything...except what I want Confused

As I just needed it to solve one problem, I've tried to avoid having to learn the details - there is quite a learning curve - and it would just take too long.

rarsa wrote:
Here is a one liner that does what you want:

Code:
awk '{ if(match($0,"ramdisk_size[ ]*=[ ]*[0-9]*")) printf(substr($0,RSTART,RLENGTH))}'  %pupdrv%/syslinux.cfg


That will handle spaces around the = sign and will return the ramdisk_size=63488 without a newline at the end.

Tried your one-liner but got the following error:

Code:
{ if(match($0,ramdisk_size[
awk: line 0: syntax error


rarsa wrote:
I'm also a novice in awk (I've just written two awk commands in my life... this being the second one) but I've found some good resources like this tutorial http://www.grymoire.com/Unix/Awk.html#uh-47

Thanks, I'll take a look at it.

Otherwise, while I have been waiting for a response to my post, I actually managed to patch together something that works and will give the right parameter regardless of which field it is in:

awk "/ramdisk_size/{for(i=1;i<=NF;i++){if($i~/ramdisk_size/)print \"set rdsize=\" $i};exit;}" isolinux.cfg >tmp_.bat
call tmp_.bat
del tmp_.bat >NUL

I got this working after looking at many AWK examples (books & internet) and a lot of trial and error. So it looks like I'll be able to finish my updated WakePup soon after all.

Very Happy
Back to top
View user's profile Send private message 
pakt


Joined: 04 Jun 2005
Posts: 1089
Location: Sweden

PostPosted: Sun 30 Oct 2005, 15:11    Post subject:  

rarsa wrote:
Can there be spaces around the '=' ?

e.g.
Code:
append root =/dev/ram0 initrd= image.gz ramdisk_size = 63488 PFILE = pup001-none-262144

In response to your question about spaces, AWK uses spaces as delimiters by default. Therefore the single field 'ramdisk_size=63488' would become three fields instead.

I hope that that variation (having spaces around the '=') in isolinux.cfg or syslinux.cfg isn't allowed by Barry's scripts, otherwise it will be back to the drawing board for me.
Back to top
View user's profile Send private message 
pakt


Joined: 04 Jun 2005
Posts: 1089
Location: Sweden

PostPosted: Sun 30 Oct 2005, 15:28    Post subject:  

rarsa wrote:
I know that you said that you only had access to awk and sed. but... do you have access to grep?

Code:
grep -o 'ramdisk_size[ ]*=[ ]*[0-9]*'  %pupdrv%/syslinux.cfg


This gives you exactly what you are asking for. In any event, That's the regular expression you want to use to find the ramdisk_size even if you are not using grep.

Just tried your 'grep' suggestion, but I don't get any output. I had to change the ' to " to work in DOS, like this:

grep -o "ramdisk_size[ ]*=[ ]*[0-9]*" syslinux.cfg

This was using 'Turbo GREP 5.5 Copyright (c) 1992, 1999 Inprise Corporation'

EDIT: Used wrong syslinux file with above example Embarassed. With isolinux.cfg, the grep expression outputs all four _complete_ lines containing the parameter Sad

I also tried with another grep I had (GNU grep 2.0 (MS-DOS rev A)), but it didn't recognize the -o flag. Sad
Back to top
View user's profile Send private message 
BarryK
Puppy Master


Joined: 09 May 2005
Posts: 7047
Location: Perth, Western Australia

PostPosted: Sun 30 Oct 2005, 21:26    Post subject:  

Anywhere my scripts have generated ramdisk_size=65536, it is without spaces.
Of course, if someone has manually edited the file that's another matter, but nowhere in any examples or documentation do I show it with spaces, so I reckon you will be safe to assume no spaces.
Back to top
View user's profile Send private message Visit poster's website 
rarsa


Joined: 29 May 2005
Posts: 3053
Location: Kitchener, Ontario, Canada

PostPosted: Sun 30 Oct 2005, 23:45    Post subject:  

patk wrote:
Tried your one-liner but got the following error:
Code:

{ if(match($0,ramdisk_size[
awk: line 0: syntax error
I just tried it again and it works in puppy, that tells me that the problem is with the awk you are using or the regular expressions evaluator it uses.

I was going for the loop too, but I found that a one liner was better. Anyway, I'm glad it's working for you.

patk wrote:
With isolinux.cfg, the grep expression outputs all four _complete_ lines containing the parameter
The -o parameter tells grep to output just the text that matches the regular expression, not the whole line. Is there another option in turbo grep that would do this?
Back to top
View user's profile Send private message Visit poster's website 
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: Mon 31 Oct 2005, 00:37    Post subject:  

try http://unxutils.sf.net
The included grep supports -o

Mark
Back to top
View user's profile Send private message Visit poster's website 
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: Mon 31 Oct 2005, 00:49    Post subject:  

with unxutils you can do:
grep ramdisk_size isolinux.cfg|sed s/^.*ramdisk_size=\([0-9]*\).*$/\1/ >test.txt

At least on WinXP.

Mark
Back to top
View user's profile Send private message Visit poster's website 
pakt


Joined: 04 Jun 2005
Posts: 1089
Location: Sweden

PostPosted: Mon 31 Oct 2005, 05:47    Post subject:  

MU wrote:
with unxutils you can do:
grep ramdisk_size isolinux.cfg|sed s/^.*ramdisk_size=\([0-9]*\).*$/\1/ >test.txt

At least on WinXP.

Thanks Mark. Seems that unxutils is for win32, but I did find some more grep's that worked with DOS (unfortunately I can't find one that supports the -o flag).

Here is the output I get with your example where isolinux.cfg contains three lines with the parameter ramdisk_size=13312:
13312
13312
13312

This would be a good solution except that I want just a single '13312' - not three. Is there a way of doing that?
Back to top
View user's profile Send private message 
Guest
Guest


PostPosted: Mon 31 Oct 2005, 06:08    Post subject:  

in linux, you could pipe it through head -n1
there should be a port of head somewhere
Back to top
pakt


Joined: 04 Jun 2005
Posts: 1089
Location: Sweden

PostPosted: Mon 31 Oct 2005, 06:40    Post subject:  

Seems I managed to solve it myself Smile

Using Mark's example and 'GNU UNIQ, textutils version 1.2' for DOS like this:

grep ramdisk_size isolinux.cfg|sed s/^.*ramdisk_size=\([0-9]*\).*$/\1/ | uniq >test.txt

...outputs a single '13312' instead of three.

Now I have two solutions...

Thanks to everyone for suggestions & info Very Happy
Back to top
View user's profile Send private message 
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: Mon 31 Oct 2005, 06:48    Post subject:  

ftp://garbo.uwasa.fi/pc/unix/gnuegrep.zip
ftp://garbo.uwasa.fi/pc/unix/sed15.zip
ftp://garbo.uwasa.fi/pc/unix/tail20.zip

from http://garbo.uwasa.fi/pc/unix.html

They work in Dosbox, but I can't get the "|" -character on my keyboard in Dosbox, so I can't test the whole expression.

try
grep ramdisk_size isolinux.cfg | sed "s/^.*ramdisk_size=\([0-9]*\).*$/\1/" | tail -n 1

Mark
Back to top
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 1 of 2 [17 Posts]   Goto page: 1, 2 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Advanced Topics » Cutting edge
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0955s ][ Queries: 11 (0.0061s) ][ GZIP on ]