Friday, 26 July 2013

fibonacci in perl script

#!/usr/bin/perl
$y=0;
@s=@ARGV;
for($i=0;$i<@s;$i++)
{
$y = $s[$i] + $y;
}
print $y."\n";


usage:  ./filename `seq 100`

fibonacci series in shell script

#!/bin/bash
y=0
s=($@)
for((i=0;i<${#s[@]};i++))
do
y=$((${s[$i]} + $y))
echo $y;
done


usage:

./filename 1 2 3
 6



find and replace in same file in perl

open(FILE,"sam");
@line=<FILE>;
close(FILE);
open(FILE1,">sam");
for($i=0;$i<@line;$i++)
{
$line[$i]=~s/4/charles/sg;
print FILE1 $line[$i];
}
close(FILE1);

Thursday, 11 July 2013

Copying the file along with folder structure

cat file_name | while read a;
 do
 tar cpof - $a | ( cd /home/praveensam.s/clamav_old_files_backup ; tar xpof - ); done

Monday, 8 July 2013