Print first 4 lines , last 3 lines and lines between starting_line and end_line from a file.

p10.sh

#!/bin/bash


line1=`head -4 /etc/passwd`
line2=`tail -3 /etc/passwd`

echo -e "First 4 lines are :\n "
echo -e "$line1\n"
echo -e "Last 3 lines are:\n "
echo -e "$line2\n"

echo "Give Starting line: "
read starting_line
echo "Give End line: "
read end_line
line3=`sed -n "$a,$b p" /etc/passwd`

echo "Lines between starting and end line:\n "
echo -e "$line3"

Post a Comment

Previous Post Next Post