Sponsored Content
Homework and Emergencies Emergency UNIX and Linux Support Logic for file copy operation Post 302468221 by raghu_shekar on Tuesday 2nd of November 2010 05:40:35 AM
Old 11-02-2010
Logic for file copy operation

Hi,
i need to copy contents from source to destination with a few conditions, Please helpme out.
Sample input file
Code:
$>cat testfile.txt
/a/b/c/d | /e/f/g/d

(d can be either a file or directory)
my conditions are:
check if destination is valid and if its a file or directory
if its a directory(i.e source is a new file and does not already exist), copy the source(file) to destination
if its a file(there s a file with the same name as source file), take backup and copy the source(file) to destination
if not both, print error msg
Here is what i have tried:
Code:
 
#!/bin/ksh
src=`cat testfile.txt |awk -F\| '{print $1}' testfile.txt`
dst=`cat testfile.txt |awk -F\| '{print $2}' testfile.txt`
#collect all invalid, or check if source and destination are valid:
if [[ ! -f $src ]];then
      echo "Source does not exist"
      exit 0
fi
if [[ ! -d $dst && -f $dst ]];then
      echo "taking backup of existing $dst and copying new file from $src"
      mv $dst $dst.BAK
      cp $src $dst
elif [[ -d $dst && ! -f $dst ]];then
      echo "copying $src to $dst"
      cp $src $dst
else
      echo "Destination directory does not exist. Please check..."
      exit 0
fi

But this doesnt seem to be working. Please help

Moderator's Comments:
Mod Comment Using code tags is good, indention even better Smilie

Last edited by zaxxon; 11-02-2010 at 07:03 AM..
 

3 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Column operation : cosne and sine operation

I have a txt file with several columns and i want to peform an operation on two columns and output it to a new txt file . file.txt 900.00000 1 1 1 500.00000 500.00000 100000.000 4 4 1.45257346E-07 899.10834 ... (4 Replies)
Discussion started by: shashi792
4 Replies

2. UNIX for Dummies Questions & Answers

Copy operation incomplete

I am logged into AIX 6.1 as a root user. I tried copying about 190GB of data to a different folder. cp -R /u01/data/scope /CY/backup I got the message: cp: Requested a write of 4096 bytes, but wrote only 3584. When the copy operation completed, I checked the /CY/backup/scope folder and... (3 Replies)
Discussion started by: shoefiend
3 Replies

3. UNIX for Beginners Questions & Answers

Copy last few lines of a file, perform math operation and iterate further

Hi, I am trying to generate a data of following order: 4 0 1 642 643 4 642 643 1283 1284 4 1283 1284 1924 1925 4 1924 1925 2565 2566 4 2565 2566 3206 3207 4 3206 3207 3847 3848 4 3847 3848 4488 4489 4 4488 4489 5129 5130 ---------------------- 4 1 2 643 644 4 643 644 1284... (6 Replies)
Discussion started by: SaPa
6 Replies
mlib_SignalConvertShift_F32_U8(3MLIB)									     mlib_SignalConvertShift_F32_U8(3MLIB)

NAME
mlib_SignalConvertShift_F32_U8, mlib_SignalConvertShift_F32_S8, mlib_SignalConvertShift_F32_S16, mlib_SignalConvertShift_F32_S32, mlib_Sig- nalConvertShift_F32S_U8S, mlib_SignalConvertShift_F32S_S8S, mlib_SignalConvertShift_F32S_S16S, mlib_SignalConvertShift_F32S_S32S - data type convert with shifting SYNOPSIS
cc [ flag... ] file... -lmlib [ library... ] #include <mlib.h> mlib_status mlib_SignalConvertShift_F32_U8(mlib_f32 *dst, const mlib_u8 *src, mlib_s32 shift, mlib_s32 n); mlib_status mlib_SignalConvertShift_F32_S8(mlib_f32 *dst, const mlib_s8 *src, mlib_s32 shift, mlib_s32 n); mlib_status mlib_SignalConvertShift_F32_S16(mlib_f32 *dst, const mlib_s16 *src, mlib_s32 shift, mlib_s32 n); mlib_status mlib_SignalConvertShift_F32_S32(mlib_f32 *dst, const mlib_s32 *src, mlib_s32 shift, mlib_s32 n); mlib_status mlib_SignalConvertShift_F32S_U8S(mlib_f32 *dst, const mlib_u8 *src, mlib_s32 shift, mlib_s32 n); mlib_status mlib_SignalConvertShift_F32S_S8S(mlib_f32 *dst, const mlib_s8 *src, mlib_s32 shift, mlib_s32 n); mlib_status mlib_SignalConvertShift_F32S_S16S(mlib_f32 *dst, const mlib_s16 *src, mlib_s32 shift, mlib_s32 n); mlib_status mlib_SignalConvertShift_F32S_S32S(mlib_f32 *dst, const mlib_s32 *src, mlib_s32 shift, mlib_s32 n); Each of these functions performs data type convert with shifting. The following equation is used: dst[i] = src[i] * 2**shift See the following table for available variations of this group of data type convert functions. Type [*] F32 F32S U8 Y S8 Y S16 Y S32 Y U8S Y S8S Y S16S Y S32S Y [*] Each row represents a source data type. Each column represents a destination data type. Each of the functions takes the following arguments: dst Destination signal array. src Source signal array. shift Left shifting factor. n Number of samples in the source signal arrays. Each of the functions returns MLIB_SUCCESS if successful. Otherwise it returns MLIB_FAILURE. See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Evolving | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ mlib_SignalConvertShift_U8_S8_Sat(3MLIB), attributes(5) 10 Nov 2004 mlib_SignalConvertShift_F32_U8(3MLIB)
All times are GMT -4. The time now is 02:38 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy