LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 05-01-2010, 11:47 PM   #76
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,999

Rep: Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190

Do you happen to know what the "10" is referring to???
Try the following and it will show you which characters you are working with:
Code:
echo "(hd0,0)" | od -A n -t c
You will notice that the piece of code you have written never fails.
 
Old 05-02-2010, 02:43 AM   #77
webhope
Member
 
Registered: Apr 2010
Posts: 184

Original Poster
Rep: Reputation: 30
What is it good for? I see characters in output
echo <string>

Edit:
Now I am going to write a script save the blocks. You know that I operate with block separately not with whole file. There for all items/blocks from array content I need to proceed through for loop and then do a search of bock and replace. Is it possible to do such search in sed? I now that sed has problems with multiline searches. It's like to search something like this:

line 1 title \n
line 2 ... \n
line 3 ... \n

and replace it...

I would better prefer to identify hole block so ... if in file exists more same titles but with different uuid, it will not be overwritten because of identical titles, but he would reconize that the next line is different from the pattern....

Last edited by webhope; 05-02-2010 at 03:06 AM.
 
Old 05-02-2010, 03:28 AM   #78
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,999

Rep: Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190
Quote:
What is it good for?
What you were supposed to see is that the 10 you refer to is the value for "\n" which will ALWAYS be at the end of an echo.
This therefore makes your test useless as it will NEVER be wrong.

Yes you can do multiline edits in sed but you will need to be careful about how you go about it.

Personally I think you need to step back and rethink what you are trying to do.
Also, as identified on several occasions, you need to test a lot more of what you are trying to do before going ahead.
Currently you are trying to change fields which may or may not actually work/be allowed.

Most of all you need to try and build your script a line at a time by trialling what you want to do on the command line first
and see what the results are. This process would save a lot of the stoppages you have been running into.
 
Old 05-02-2010, 03:57 AM   #79
webhope
Member
 
Registered: Apr 2010
Posts: 184

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by grail View Post
Currently you are trying to change fields which may or may not actually work/be allowed.
Actually it looks that the array asignment work well...

Quote:
Originally Posted by grail View Post
Most of all you need to try and build your script a line at a time by trialling what you want to do on the command line first
and see what the results are. This process would save a lot of the stoppages you have been running into.
I guess this will be complicated?

Edit:
Quote:
Originally Posted by grail View Post
Yes you can do multiline edits in sed but you will need to be careful about how you go about it.
From your answer I am still not sure ... does it mean the replace pattern for sed is standard? Or the process will be more complicated? And do you think I need call sed for every single block from the $content variable? Or can sed accept a array ($content) and to do such loop and process every item in array automatically. Now I am prepared to do a while cycle for the sed.

Last edited by webhope; 05-02-2010 at 05:07 AM.
 
Old 05-02-2010, 05:19 AM   #80
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,999

Rep: Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190
Quote:
Actually it looks that the array asignment work well...
Actually, I was referring to the changes you are making in the menu.lst not having been tested.

Quote:
From your answer I am still not sure ... does it mean the replace pattern for sed is standard? Or the process will be more complicated? And do you think I need call sed for every single block from the $content variable? Or can sed accept a array ($content) and to do such loop and process every item in array automatically. Now I am prepared to do a while cycle for the sed.
It may be possible to send the value of the relevant part of the array to sed, but as i have said before, I would be changing the uuid once and sending that to sed as root, for example, would typically always be the same.
As with my previous post, really the best way to see what will work is at the command line on a test scenario.
 
Old 05-03-2010, 02:55 AM   #81
webhope
Member
 
Registered: Apr 2010
Posts: 184

Original Poster
Rep: Reputation: 30
Unhappy

I found something unsolved yet in the script. At the beginning needed to be a code that decides about way of conversion. It means for all blocks I need to convert from uuid to hd or from hd to uuid. This thing I forgot. Now I created this code:

Code:
block_new="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"

((fst++)); [[ $fst -eq 1 ]] && first=$(echo "$block_new" | awk '/(.*UUID=.*)|(\(hd)/ {print $1}')
echo $first;
In the $1 should be the first found "hd(" or "UUID". It works good if it is just one line. But if it is more lines of block, than it failes. Can you tell me how to capture only 1 result? It means either "hd(" or "UUID" to $1? Thanks

Edit:
One more awk. This code should escaped characters of class [/+()[]]
Code:
block_new="   /   +  (      ) [ ] "  
p=$( echo $block_new |  awk '{ x=gensub(/([/+()[]])/,"//\\1","g");  print x}')
echo $p
also not working :-(

Last edited by webhope; 05-03-2010 at 05:39 AM.
 
Old 05-03-2010, 05:09 AM   #82
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,999

Rep: Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190
For your first problem set a variable and once it is a value do not print anymore.

Second problem:
1. /.*/ - this is a complete waste as once again, refer to previous posts, it is ALWAYS true so not required
2. What do you expect from echo $p?
 
Old 05-03-2010, 05:17 AM   #83
webhope
Member
 
Registered: Apr 2010
Posts: 184

Original Poster
Rep: Reputation: 30
Edit 1:
Quote:
Originally Posted by grail View Post
For your first problem set a variable and once it is a value do not print anymore.
But the problem is that it
Code:
awk '/(UUID=)|(\(hd)/'
returns whole line instead just "UUID" value or "hd(" . I need this two possibilities for if condition.

Edit 2:
Quote:
Originally Posted by grail View Post
2. What do you expect from echo $p?
It was just a text to escape some characters. I wanted to prepare pattern for sed.

Code:
p=$( echo $block_new |  awk '{ x=gensub(   /([/+()[]])/  ,"//\\1","g");  print x}')
echo $p
Still the same problem (nothing escaped)

Last edited by webhope; 05-03-2010 at 05:42 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 01:03 PM.

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