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
|