开发者

How would I find a variable in a line and use cut to retrieve the value

The problem is essentially this, I need to be able to search for a variable within a a line that I have already cat'ed out from /proc/cmdline. Then be able to cut the value of this variable out (in this case I want to cut out the value of Disktype).

*It should be noted that this will be in the PXE boot environment so most other language tools won't be available and the variable and value can differ in where it appears in /proc/cmdline.

So essentially If I cat out /proc/cmdline I could get this:

centos-workstation-x86_64/vmlinuz initrd=centos-workstation-x86_64/initrd.img locale=en_US Disktype=Fresh

or this

rhel6-workstation-x86_64/vmlinuz initrd=rhel6-workstation-x86_64/initrd.img Disktype=Large locale=en_US 

or any other var开发者_运维技巧iation with even more other variables set up for PXE.

*clarification this will be part of a larger kickstart file

** For those that may wonder why this might be useful, using this I will be specifying later a case statement in the kickstart that matches what was thrown into Disktype to determine what partition.cfg to use during the installation process.


In awk it's easy if you correctly set th Record Separator and Field Separator:

awk  '/Disktype/{print $2}' RS=" " FS==

cut doesn't really lend itself to this task:

tr " " "\n" | grep Disktype | cut -f 2 -d =

You could also do it using sed:

sed -n 's/^.*Disktype=\([^ ]\+\)/\1/p'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜