I have a file say test with following values
Linux
Solaris
Fedora
Ubuntu
AIX
HPUX
How to add a line with system hostname after the line matching AIX? If I do
echo `hostname` >> test
system hostname comes at the last after HPUX.
Could you please try following awk
and let me know if this helps you.
awk -v host=$(hostname) '$0 == "AIX"{print $0 RS host;next} 1' Input_file
EDIT: Adding 1 more solution too here.
awk -v host=$(hostname) '{printf("%s%s\n",$0,$0=="AIX"?RS host:"")}'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With