Programming Tutorials

(追記) (追記ここまで)

Print contents of a file using Shell Script

By: Vivek G in Linux Tutorials on 2011年01月29日 [フレーム]

This shell script prints contents of file from given line number to next given number of lines. For e.g. If we called this script as printfile and run as $ printfile 5 5 myfile , Here print contents of 'myfile' file from line number 5 to next 5 line of that file.
if [ $# -eq 0 ] 
then
 echo "0ドル:Error command arguments missing!"
 echo "Usage: 0ドル start_line uptoline filename"
 echo "Where start_line is line number from which you would like to print file"
 echo "uptoline is line number upto which would like to print"
 echo "For eg. 0ドル 5 5 myfile"
 echo "Here from myfile total 5 lines printed starting from line no. 5 to"
 echo "line no 10."
 exit 1
fi
#
# Look for sufficent arg's
#
 if [ $# -eq 3 ]; then
	if [ -e 3ドル ]; then
 	 tail +1ドル 3ドル | head -n2ドル
 else
 	 echo "0ドル: Error opening file 3ドル" 
	 exit 2
	fi 
 else
 echo "Missing arguments!"	
 fi



(追記) (追記ここまで)


Add Comment

JavaScript must be enabled for certain features to work
* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in Linux )

Latest Articles (in Linux)

(追記) (追記ここまで)
(追記) (追記ここまで)

Related Tutorials

AltStyle によって変換されたページ (->オリジナル) /