Custom Search

Monday, 14 May 2012

Linux shell script to accept two file names, if both files exist then contents of first file should appended to second. If second file does not exist then create it with the contents of first file, Unix Program to perform operation on file

Linux shell script to accept two file names, if both files exist then contents of first file should appended to second. If second file does not exist then create it with the contents of first file, Unix Program to perform operation on file



Program
clear


echo"Enter first file name:"
read f1
echo"Enter second file name:"
read f2


if test -f$f1


then
echo " File $f1 is already exist"
else
echo "File created successfully"
cat > $f1
fi
if test -f $f2
then
echo "File $f2 is already exist"
else
echo "File created successfully"
 cat > $f2
fi
cat < $f1>>$f2


Output


Enter first file name:tmp1.sh
Enter second file name:tmp2.sh
File tmp1 is already exist.
File tmp2 created successfully.
Note:All the content of tmp1 is copied to tmp2. 

No comments:

Post a Comment

Laptops