LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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


Reply
  Search this Thread
Old 04-30-2010, 03:49 PM   #61
webhope
Member
 
Registered: Apr 2010
Posts: 184

Original Poster
Rep: Reputation: 30

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.
 
Old 04-30-2010, 11:54 PM   #62
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,011

Rep: Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194
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
 
Old 05-01-2010, 01:21 AM   #63
webhope
Member
 
Registered: Apr 2010
Posts: 184

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by grail View Post
Also, --re-interval is not required here
$hd includes gensub qualifier interval.

Edit:
How should be the regexp?
Code:
/hd\\(0,2\\)/
or
Code:
/hd\(0,2\)/
?


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.
 
Old 05-01-2010, 04:25 AM   #64
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,011

Rep: Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194
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")'
 
Old 05-01-2010, 06:25 AM   #65
webhope
Member
 
Registered: Apr 2010
Posts: 184

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by grail View Post
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.
 
Old 05-01-2010, 06:30 AM   #66
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by webhope View Post
What is "ie"?
Strictly i.e., it is short for the Latin expression id est meaning "that is".
 
Old 05-01-2010, 06:33 AM   #67
webhope
Member
 
Registered: Apr 2010
Posts: 184

Original Poster
Rep: Reputation: 30
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
???
 
Old 05-01-2010, 06:34 AM   #68
webhope
Member
 
Registered: Apr 2010
Posts: 184

Original Poster
Rep: Reputation: 30
Wink

Quote:
Originally Posted by catkin View Post
Strictly i.e., it is short for the Latin expression id est meaning "that is".
Quite confusing. Because IE means Internet Explorer
 
Old 05-01-2010, 06:37 AM   #69
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by webhope View Post
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.
 
Old 05-01-2010, 07:20 AM   #70
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,011

Rep: Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194
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
 
Old 05-01-2010, 08:13 AM   #71
webhope
Member
 
Registered: Apr 2010
Posts: 184

Original Poster
Rep: Reputation: 30
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.
 
Old 05-01-2010, 09:03 AM   #72
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,011

Rep: Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194
I think you better have a look at some bash programming sites and how arrays work.

http://tldp.org/LDP/abs/html/arrays.html
 
Old 05-01-2010, 09:16 AM   #73
webhope
Member
 
Registered: Apr 2010
Posts: 184

Original Poster
Rep: Reputation: 30
Well this works fine
Code:
echo ${content[*]};
 
Old 05-01-2010, 09:26 AM   #74
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,011

Rep: Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194
Correct
 
Old 05-01-2010, 11:50 AM   #75
webhope
Member
 
Registered: Apr 2010
Posts: 184

Original Poster
Rep: Reputation: 30
Lightbulb

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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Migrate Regexp from SED to AWK cgcamal Programming 9 04-23-2010 10:32 PM
[SOLVED] awk: how can I assign value to a shell variable inside awk? quanba Programming 6 03-23-2010 02:18 AM
awk regexp for one character match nemobluesix Linux - General 7 02-16-2009 10:50 PM
Volume has problems including no uuid in /dev/disk/by-uuid abejarano Linux - Hardware 3 12-31-2008 08:41 PM
shell command using awk fields inside awk one71 Programming 6 06-26-2008 04:11 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:05 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration