Sponsored Content
Full Discussion: Perl script solution
Top Forums Shell Programming and Scripting Perl script solution Post 302422024 by webhope on Monday 17th of May 2010 09:58:19 AM
Old 05-17-2010
that was mistake:
not print x NFR
but
print x

I gave you simplified form of code.

Quote:
Originally Posted by zaxxon
Why must it be awk?

---------- Post updated at 02:37 PM ---------- Previous update was at 02:25 PM ----------

Code:
$> cat infile
title Sata Mandriva
kernel /boot/vmlinuz
initrd /boot/initrd.img
$> echo "$block"| awk '/(kernel|initrd)/ && f!=1 {sub(/ /,"XXX"); f=1; print; next}1' f=0
title Sata Mandriva
kernelXXX/boot/vmlinuz
initrd /boot/initrd.img

I must to explain you what I want to do.

Originally. I had something like ... kernel (hd0,2) ... root=(hd0,2) .... I replaced it with ...
Code:
kernel (UUID=theuuid) ... root=(UUID=theuuid)
initrd (UUID=theuuid)

It is not ideal but what I do in previous code is that I replace (hd?,?) for uuid and uuid for (hd?,?)

My code was:
Code:
block=$( echo "$block" | awk '{ x=gensub(/(kernel|init)( +)\(UUID=[-0-9a-f]*\)/,"uuid '$two'\\\\n\\1 ","g"); print x}' );

Original input text was like:
Code:
title Sata Mandriva\nkernel (UUID=eab515e9-bc3e-4024-9f01-55fddaa0fb1c)/boot/vmlinuz BOOT_IMAGE=linux root=(UUID=eab515e9-bc3e-4024-9f01-55fddaa0fb1c) resume=(UUID=e12487ff-6d6f-44c4-9e03-33f545b3b798) splash=silent vga=788 uuid UUID=eab515e9-bc3e-4024-9f01-55fddaa0fb1c\ninitrd /boot/initrd.img

Includes \n twice fot newline character.
See:
Code:
\nkernel (UUID=
\ninitrd /boot/initrd.img

I tried your code, but it result in:
Code:
titleXXXSata Mandriva kernel (UUID=eab515e9-bc3e-4024-9f01-55fddaa0fb1c)/boot/vmlinuz BOOT_IMAGE=linux root=(UUID=eab515e9-bc3e-4024-9f01-55fddaa0fb1c) resume=(UUID=e12487ff-6d6f-44c4-9e03-33f545b3b798) splash=silent vga=788 uuid UUID=eab515e9-bc3e-4024-9f01-55fddaa0fb1c\ninitrd /boot/initrd.img



---------- Post updated at 03:58 PM ---------- Previous update was at 03:30 PM ----------

Smilie

What I want to do:
The 1st found result from (..|..) to give on separete line with uuid:
change this:
Code:
kernel (UUID=eab515e9-bc3e-4024-9f01-55fddaa0fb1c) /boot ...
initrd (UUID=eab515e9-bc3e-4024-9f01-55fddaa0fb1c) /boot

to this:
Code:
uuid UUID=eab515e9-bc3e-4024-9f01-55fddaa0fb1c
kernel /boot...
initrd /boot...

It is important to specify we look for kernel or initrd. "initrd (UUID=... " or "kernel (UUID=..." .
Because there also can occur words like "unhide (UUID=" or "hide (UUID=" or similar.

Last edited by webhope; 05-17-2010 at 11:08 AM..
 

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Please suggest a script or solution?

I have to solve a programming problem for my wife who is engaged in Research in Breast Cancer. 1. She has frequently to search a long single line of alphabetic characters (lower case) for an exact match of a string. e.g.... (4 Replies)
Discussion started by: nmsinghe
4 Replies

2. UNIX for Dummies Questions & Answers

How to get the script corrected to get the solution

Can anyone help it out, My Requirement: Actually i grep for the items in the atrblist (Result of it will provide the line where the item present and also the next line of where it presents)then it will be stored in $i.txt From tat result i wil grep 2nd word after getdate() word and store... (2 Replies)
Discussion started by: prsam
2 Replies

3. Shell Programming and Scripting

Expect Script - Need help to find solution

I am facing below issue with my script. below is one of the test out of 50 test from the tool which i m trying to automate. the test may show up or may not depending upon the previous results and also from the test some inputs may be asked or may not be asked depending upon previous results so you... (1 Reply)
Discussion started by: snehalb
1 Replies

4. Shell Programming and Scripting

Looking for a perl-compatible regex solution

This is for PHP preg_match code - which is PCRE therefore looking for a perl compatible suggestion I have this line returned I want to match and return.. I want to match the two instances of string ending 'ABCXYZ' into an array. And on second element (ie. RootABCXYZ) only return the word... (4 Replies)
Discussion started by: deadyetagain
4 Replies

5. Shell Programming and Scripting

Script solution as singleline ?

Hello My script has following line and output find path -type d | awk -F "/" 'NF == 4{print $3}' path/custype=Type1/logdate=20160414 path/custype=Type11122/logdate=20160414 But I need following output that I need custtype information between "" like... (4 Replies)
Discussion started by: msuluhan
4 Replies
All times are GMT -4. The time now is 07:51 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy