The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #6 (permalink)  
Old 03-19-2008
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,098
input:

Code:
first
second
forth
fifth

output:

Code:
first
second
third
forth
fifth


Code:
line=`cat a | wc -l`
half=`expr $line / 2`
nawk -v s="$half" '{
if(NR<=s) 
print
}' a
echo "third"
nawk -v s="$half" '{
if(NR>s) 
print
}' filename