hello everybody,
I have some files in directory.each file contain some data.
my requirement is add the count of each line of file in head of each file.
any advice !!!!!!!!
Here is absic example now you can change it as per ur requirement
for filename in *;
do
count=`wc -l $filename |awk '{ print $1 }'`
echo "$count in $filename"
# Here add comand to add the count of each line of file in head of file
done
The following code for basic. It will work for only one file. If you need to implement for all files.
use strict;
use warnings;
open FH,"<file" or die "Can't Open $!";
my @array;
while(<FH>)
{
push(@array,$_);
}
my $var=$#array+1;
close FH;
open FH,">file" or die "Can't Open $!";
print FH "$var\n";
print FH "@array";
Use the following script for getting the line count of the each file in a directory in head of the each file.
for file in `ls .`
do
if [ -f $file ]
then
var=`wc -l $file | cut -d ' ' -f 1`
`sed -i "1i \$var" $file`
fi
done
thanks a lot rehka ...its working....