View Single Post

  #2 (permalink)  
Old 12-07-2007, 06:32 PM
anilvrathod's Avatar
anilvrathod anilvrathod is offline
Junior Member
User
 
Join Date: Dec 2007
Location: Pune
My distro: Red Hat
Posts: 13
Rep Power: 0
anilvrathod is on a distinguished road
Default Shell Scripting .......................

Dear Friend
Qus:-
I am doing a simple echo of lines and words from a file and I also want to echo the number of lines and words to it.

Ans:

# vi example.sh
#!/bin/bash
# read a file line by line
file=/file_path_for_count
x=0
lns=`wc -l $file`
y=`expr "$lns" : '\([0-9]*\)'`
****or**** use one of them y statement
y=`cat $file | wc -l `

while [ "$x" -lt "$y" ]
do
let x=x+1
head -n $x $file | tail -n 1
done
exit 0

Reply With Quote