Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to
LinuxQuestions.org , a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free.
Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please
contact us . If you need to reset your password,
click here .
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a
virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month.
Click here for more info.
04-30-2010, 03:49 PM
#61
Member
Registered: Apr 2010
Posts: 184
Original Poster
Rep:
Where is problem:
Code:
echo $block_new | awk --re-interval '{sub("'$hd'","'$uuid'","g") } $0'
Nothing outputs. It should output the $block_new with hd to uuid replaced.
04-30-2010, 11:54 PM
#62
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,011
Awk sub command:
Code:
sub(regexp, replacement [, target])
All of this - '{sub("'$hd'","'$uuid'","g") } $0' - needs to be in the above format
Assuming you wish to do a global substitution (ie the "g" in your code), you can use:
Code:
gsub(regexp, replacement [, target])
Also, --re-interval is not required here
05-01-2010, 01:21 AM
#63
Member
Registered: Apr 2010
Posts: 184
Original Poster
Rep:
Quote:
Originally Posted by
grail
Also, --re-interval is not required here
$hd includes gensub qualifier interval.
Edit:
How should be the regexp?
or
?
awk: warning: escape sequence `\(' treated as plain `('
Edit
I think that the double escaped backslash should be ok:
Code:
hd=${hd//(/\\\\(}; # left bracket escape
hd=${hd//)/\\\\)}; # right bracket escape
because this
Code:
hd=${hd//(/\\(}; # left bracket escape
hd=${hd//)/\\)}; # right bracket escape
returns awk: warning: escape sequence `\(' treated as plain `('
Edit:
But through ... nothing been replaced :-/
The block output still looks like:
Code:
title Sata Mandriva kernel (hd0,2)/boot/vmlinuz BOOT_IMAGE=linux root=UUID=eab515e9-bc3e-4024-9f01-55fddaa0fb1c resume=UUID=e12487ff-6d6f-44c4-9e03-33f545b3b798 splash=silent vga=788 initrd (hd0,2)/boot/initrd.img
And this was a try to replace (hd0,2) to uuid
Last edited by webhope; 05-01-2010 at 02:05 AM .
05-01-2010, 04:25 AM
#64
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,011
So now you are putting UUID at the front of "/boot/vmlinuz"?
Again I would ask if you have tested that this will actually work, ie is having UUID there plausible, have you tested it?
This worked for me without errors:
Code:
echo "(hd0,2)/boot/vmlinuz" | awk 'gsub(/\(hd0,2\)/,"uuid")'
05-01-2010, 06:25 AM
#65
Member
Registered: Apr 2010
Posts: 184
Original Poster
Rep:
Quote:
Originally Posted by
grail
So now you are putting UUID at the front of "/boot/vmlinuz"?
Again I would ask if you have tested that this will actually work, ie is having UUID there plausible, have you tested it?
This worked for me without errors:
Code:
echo "(hd0,2)/boot/vmlinuz" | awk 'gsub(/\(hd0,2\)/,"uuid")'
What is "ie"?
I didn't test. Never mind. Grub boot manager has a editor to change boot item before booting.
Problem is elsewhere. NOT
hd(0,2) BUT
(hd0,2) - my fault!
Last edited by webhope; 05-01-2010 at 06:36 AM .
05-01-2010, 06:30 AM
#66
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Quote:
Originally Posted by
webhope
What is "ie"?
Strictly i.e., it is short for the Latin expression
id est meaning "that is".
05-01-2010, 06:33 AM
#67
Member
Registered: Apr 2010
Posts: 184
Original Poster
Rep:
One more problem in the regex replace. This is the effect: UUID=-4033-55
Code:
++ echo title Sata Mandriva kernel '(hd0,2)/boot/vmlinuz'
++ awk '{gsub(/\(hd0,2\)/,"UUID="eab515e9-bc3e-4024-9f01-55fddaa0fb1c"") } $0'
+ block_new='title Sata Mandriva kernel UUID=-4033-55/boot/vmlinuz
???
05-01-2010, 06:34 AM
#68
Member
Registered: Apr 2010
Posts: 184
Original Poster
Rep:
Quote:
Originally Posted by
catkin
Strictly i.e., it is short for the Latin expression
id est meaning "that is".
Quite confusing. Because IE means Internet Explorer
05-01-2010, 06:37 AM
#69
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Quote:
Originally Posted by
webhope
Quite confusing. Because IE means Internet Explorer
And Indo-European and Industrial Engineer(ing)!
EDIT: but none of these was credible in context
Last edited by catkin; 05-01-2010 at 06:44 AM .
05-01-2010, 07:20 AM
#70
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,011
Quote:
"UUID="eab515e9-bc3e-4024-9f01-55fddaa0fb1c""
Quotes around the actual UUID are not required, should be:
Code:
"UUID=eab515e9-bc3e-4024-9f01-55fddaa0fb1c"
Also, sorry about the "ie." thing, it is quite common place in english the same as "eg." to mean for example.
On the other hand not nearly as confusing as the czech in some of your posts
05-01-2010, 08:13 AM
#71
Member
Registered: Apr 2010
Posts: 184
Original Poster
Rep:
OK. Now I try to assign the $block_new back to the content:
Code:
content[$i]=$block_new;
echo $content;
Strange is the output. It looks like the $content was overwriten by $block_new:
Code:
title Sata Mandriva kernel (hd0,2)/boot/vmlinuz BOOT_IMAGE=linux root=(hd0,2) resume=UUID=e12487ff-6d6f-44c4-9e03-33f545b3b798 splash=silent vga=788 initrd (hd0,2)/boot/initrd.img
The content of $content. We should see alll block of menu.lst keeped in memory.
But in real, $block_new should be placed to content[0]
Last edited by webhope; 05-01-2010 at 08:16 AM .
05-01-2010, 09:03 AM
#72
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,011
I think you better have a look at some bash programming sites and how arrays work.
http://tldp.org/LDP/abs/html/arrays.html
05-01-2010, 09:16 AM
#73
Member
Registered: Apr 2010
Posts: 184
Original Poster
Rep:
Well this works fine
Code:
echo ${content[*]};
05-01-2010, 09:26 AM
#74
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,011
Correct
05-01-2010, 11:50 AM
#75
Member
Registered: Apr 2010
Posts: 184
Original Poster
Rep:
I did this:
If uuid is not found in blkid list, then:
Code:
echo "Enter device:"; echo "Pattern: (hd0,0)"; read hd
[[ "$(echo $hd | od -A n -t dC)" -eq 10 ]] && hd="hd(0,0)"
Nice way how to use od
All times are GMT -5. The time now is 12:05 AM .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know .
Latest Threads
LQ News