-1

I want to add some content to the end of line. below is the example.

created by imagebuilder
default=0
fallback=1
timeout=0
hiddenmenu

title Amazon Linux 2016.03 (4.4.11-23.53.amzn1.x86_64)
root (hd0,0)
kernel /boot/vmlinuz-4.4.11-23.53.amzn1.x86_64 root=LABEL=/ console=tty1 console=ttyS0  
initrd /boot/initramfs-4.4.11-23.53.amzn1.x86_64.img

I want to add transparent_hugepage=never in the end of line which starts with kernel. Just like below

# created by imagebuilder
default=0
fallback=1
timeout=0
hiddenmenu

title Amazon Linux 2016.03 (4.4.11-23.53.amzn1.x86_64)
root (hd0,0)
kernel /boot/vmlinuz-4.4.11-23.53.amzn1.x86_64 root=LABEL=/ console=tty1 console=ttyS0 transparent_hugepage=never
initrd /boot/initramfs-4.4.11-23.53.amzn1.x86_64.img

How to do that using sed command. I tried many posts on the site but none is working in my case.

Shailesh Sutar
  • 261
  • 3
  • 13

1 Answers1

2

With GNU sed:

sed 's/^kernel .*/& transparent_hugepage=never/' file

If you want to edit your file "in place" use sed's option -i.

Cyrus
  • 69,405
  • 13
  • 65
  • 117
  • See: `man sed` and [The Stack Overflow Regular Expressions FAQ](http://stackoverflow.com/a/22944075/3776858) – Cyrus Jul 17 '16 at 22:20