Bash - Display a segment of a file

# when only the start_line is specified, a range of 10 lines before and after # that line will be displayed. when start_line and end_line are specified, those # lines and all those between will be displayed # # @param String $filename the text file with the content # @param Integer $start # @param Integer Optional $end # # Examples: # # Display lines 90 - 110. Line 100 is the middle line of content # $ seg error.log 100 # # Display lines 100 through 140. # $ seg error.log 100 140 # function seg() { range=10 filename=$1 if [[ -z $3 ]]; then start=$( calc $2-$range) end=$(calc $2+$range) else start=$2 end=$3 fi awk "NR >= $start && NR <= $end " $filename }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.