Have a text file that contains:
Want to extract all lines between "=================" and put the contents into a file name ([x|z]host|jail)[N].txt for each host.
Note the host may be "xhost" "zhost" or "jail"
For example:
# cat xhost1.txt
line with text
second line with text
third line with text
#cat zhost2.txt
line with text
second line with text
third line with text
fourth line with text
fifth line with text
Unfortunately all I get if print to stdout is the hostname (host1) and that is it. If printing to the file ($1.txt) I'm not getting any file.
Thanks
Code:
xhost1
line with text
second line with text
third line with text
=======================
zhost2
line with text
second line with text
third line with text
fourth line with text
fifth line with text
======================
zhost3
line with text
second line with text
======================
jail4
line with text
second line with text
third line with text
======================
Want to extract all lines between "=================" and put the contents into a file name ([x|z]host|jail)[N].txt for each host.
Note the host may be "xhost" "zhost" or "jail"
For example:
# cat xhost1.txt
line with text
second line with text
third line with text
#cat zhost2.txt
line with text
second line with text
third line with text
fourth line with text
fifth line with text
Code:
awk '
{ RS = "================================="; FS = "\n" }
($1 == "^xhost") {print $0}
' myfile > $1.txt
Unfortunately all I get if print to stdout is the hostname (host1) and that is it. If printing to the file ($1.txt) I'm not getting any file.
Thanks