I am writing a bash script with several menus. Instead of bloating my script with a bunch of echo commands to print banners above the different menus, I created a file which contains all my banners. I am trying to use sed (tried awk first but experiencing the same issue) to grab specific lines of the file and place them in a variable in the script. Then I call the variable once for my banner. What is happening is the correct lines from the file along with the contents of my directory are being placed in the variable.
Here is how I am assigning the lines of the file to a variable:
Code:
BANNER1=$(sed -n 1,3p banners.txt)
BANNER2=$(sed -n 4,6p banners.txt)
BANNER3=$(sed -n 7,9p banners.txt)
BANNER4=$(sed -n 10,12p banners.txt)
BANNER5=$(sed -n 13,15p banners.txt)
BANNER6=$(sed -n 16,18p banners.txt)
BANNER7=$(sed -n 19,21p banners.txt)
Contents of the file:
>cat -n banners.txt
1 ******************************************************
2 * 1st Floor Lab Device *
3 ******************************************************
4 ******************************************************
5 * 3rd Floor Lab Devices *
6 ******************************************************
7 ******************************************************
8 * DCK Lab Devices List *
9 ******************************************************
10 ******************************************************
11 * All Lab Devices List *
12 ******************************************************
13 ******************************************************
14 * Lab Terminal Servers *
15 ******************************************************
16 ******************************************************
17 * Main - Menu *
18 ******************************************************
19 ******************************************************
20 * Classic Device List *
21 ******************************************************
and output
****************************************************** banners.txt History.log lab_devices.v3.sh labhostlist.txt lab_ips_3-4-15.txt old-lab_devices.v2.sh Lab Terminal Servers banners.txt History.log lab_devices.v3.sh labhostlist.txt lab_ips_3-4-15.txt old-lab_devices.v2.sh ******************************************************
What should have been displayed is
******************************************************
* 3rd Floor Lab Devices *
******************************************************
I am using an echo command to output the variable
[code]
echo $BANNER3
[\code]
I get the same results using AWK in this manner:
Code:
BANNER1=$( awk 'NR < 4 ' banners.txt)
BANNER2=$( awk 'NR > 3 && NR < 7 ' banners.txt )
BANNER3=$( awk 'NR > 6 && NR < 10 ' banners.txt )
BANNER4=$( awk 'NR > 9 && NR < 13 ' banners.txt )
BANNER5=$( awk 'NR > 12 && NR < 16 ' banners.txt )
BANNER6=$( awk 'NR > 15 && NR < 19 ' banners.txt )
BANNER7=$( awk 'NR > 18 ' banners.txt )
I have tried several variations with spaces and single/double quotes but nothing seems to help. I just can not figure out what i am missing.