Issues in Csv file transfer copy from one dir to another


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Issues in Csv file transfer copy from one dir to another
# 1  
Old 05-29-2015
Error Issues in Csv file transfer copy from one dir to another

Hi Unix community,

I got this code from you guys and I tried to modify it to use for my csv dir transfer
basically i want the .csv file to copy itself and populate it to the archive dir.
Code:
#!/bin/ksh
dir1="/home/pumela/unixtestprod"
cd "$dir1"
echo "code is running"
for srcd in /home/pumela/unixtestprod/archive
do    targetd=${srcd#*/}
    if [ ! -d "$srcd" ] || [ ! -d "$targetd" ]
    then    continue    # Source or target directory does not exist.
    fi
    cd "$srcd" > /dev/null
    for file in *.txt
    do    if [ "$file" = '*.csv' ]
        then    break    # No *.csv files to move in this directory
        else    echo mv *.txt "$dir1/$targetd"    # Move the files
            break
        fi
    done
    cd - > /dev/null
done

I tried executing it but it doesn't work. kindly advise me.
Code:
/home/pumela/unixtestprod ls
archive         pumelatxf.ksh  dev             kshfiles        projects        test.csv        testdir
pumela@vampyrtest Non Production
/home/pumela/unixtestprod ksh pumelatxf.ksh
code is running
pumela@vampyrtest Non Production
/home/pumela/unixtestprod


Last edited by phumaree; 05-29-2015 at 03:23 PM..
# 2  
Old 05-29-2015
Please use code tags, not icode tags.
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 05-29-2015
Quote:
Originally Posted by phumaree
Hi Unix community,

I got this code from you guys and I tried to modify it to use for my csv dir transfer
basically i want the .csv file to copy itself and populate it to the archive dir.
Code:
#!/bin/ksh
dir1="/home/pumela/unixtestprod"
cd "$dir1"
echo "code is running"
for srcd in /home/pumela/unixtestprod/archive
do    targetd=${srcd#*/}
    if [ ! -d "$srcd" ] || [ ! -d "$targetd" ]
    then    continue    # Source or target directory does not exist.
    fi
    cd "$srcd" > /dev/null
    for file in *.txt
    do    if [ "$file" = '*.csv' ]
        then    break    # No *.csv files to move in this directory
        else    echo mv *.txt "$dir1/$targetd"    # Move the files
            break
        fi
    done
    cd - > /dev/null
done

I tried executing it but it doesn't work. kindly advise me.
Code:
/home/pumela/unixtestprod ls
archive         pumelatxf.ksh  dev             kshfiles        projects        test.csv        testdir
pumela@vampyrtest Non Production
/home/pumela/unixtestprod ksh pumelatxf.ksh
code is running
pumela@vampyrtest Non Production
/home/pumela/unixtestprod

Since you changed the tabs in my code to spaces (so code at the same level is no longer lined up), I almost didn't recognize my code. Smilie

If you're going to modify my code to move CSV files instead of TXT files, you need to change all four occurrences of *.txt to *.csv; not just two of them.

And, of course, after you fix that; if the output shows that it has correctly determined which files to move, you'll have to remove the echo to make it actually move the files for you.
# 4  
Old 05-29-2015
Quote:
Originally Posted by Don Cragun
Since you changed the tabs in my code to spaces (so code at the same level is no longer lined up), I almost didn't recognize my code. Smilie

If you're going to modify my code to move CSV files instead of TXT files, you need to change all four occurrences of *.txt to *.csv; not just two of them.

And, of course, after you fix that; if the output shows that it has correctly determined which files to move, you'll have to remove the echo to make it actually move the files for you.
I got some issues after I re evaluate and modify the script:

pumelatxf.ksh
Code:
#!/bin/ksh
dir1="/home/user/pumela/"
cd "$dir1"
for srcd in /home/user/pumela/archive
do    targetd=${srcd#*/}
    if [ ! -d "$srcd" ] || [ ! -d "$targetd" ]
    then    continue    # Source or target directory does not exist.
    fi
    cd "$srcd" > /dev/null
    for file in *.csv
    do    if [ "$file" = '*.csv' ]
        then    break    # No *.csv files to move in this directory
        else    echo mv *.csv "$dir1/$targetd"    # Move the files
            break
        fi
    done
    cd - > /dev/null
done

Code:
pumela@vampyrtest Non Production
$ ls
archive  dev  pumelatxf.ksh  test.csv

pumela@vampyrtest Non Production
$ ksh pumelatxf.ksh
-bash: ksh: command not found

pumela@vampyrtest Non Production
$


Last edited by phumaree; 05-29-2015 at 09:23 PM.. Reason: issues found update
# 5  
Old 05-29-2015
In post #1 in this thread, you showed us a terminal session including the results of running ls and this script:
Code:
/home/pumela/unixtestprod ls
archive         pumelatxf.ksh  dev             kshfiles        projects        test.csv        testdir
pumela@vampyrtest Non Production
/home/pumela/unixtestprod ksh pumelatxf.ksh
code is running
pumela@vampyrtest Non Production
/home/pumela/unixtestprod

and it clearly shows that you found ksh and used it to run this script. Then in post #4 you showed us a similar terminal session:
Code:
pumela@vampyrtest Non Production
$ ls
archive  dev  pumelatxf.ksh  test.csv

pumela@vampyrtest Non Production
$ ksh pumelatxf.ksh
-bash: ksh: command not found

pumela@vampyrtest Non Production
$

and ksh can no longer be found. What did you change between those two terminal sessions other than fixing pumelatxf.ksh (which will have absolutely no effect on anything when you are not running code in that script)?

What output do you get from running the commands?:
Code:
printf '%s\n' "$PATH"
uname -a
ls -l /bin/ksh /usr/bin/ksh

# 6  
Old 05-30-2015
Quote:
Originally Posted by Don Cragun
In post #1 in this thread, you showed us a terminal session including the results of running ls and this script:
Code:
/home/pumela/unixtestprod ls
archive         pumelatxf.ksh  dev             kshfiles        projects        test.csv        testdir
pumela@vampyrtest Non Production
/home/pumela/unixtestprod ksh pumelatxf.ksh
code is running
pumela@vampyrtest Non Production
/home/pumela/unixtestprod

and it clearly shows that you found ksh and used it to run this script. Then in post #4 you showed us a similar terminal session:
Code:
pumela@vampyrtest Non Production
$ ls
archive  dev  pumelatxf.ksh  test.csv

pumela@vampyrtest Non Production
$ ksh pumelatxf.ksh
-bash: ksh: command not found

pumela@vampyrtest Non Production
$

and ksh can no longer be found. What did you change between those two terminal sessions other than fixing pumelatxf.ksh (which will have absolutely no effect on anything when you are not running code in that script)?

What output do you get from running the commands?:
Code:
printf '%s\n' "$PATH"
uname -a
ls -l /bin/ksh /usr/bin/ksh

The difference is: for the first post, I am using telnet. . . but later on, I migrated all my files to other client terminal, for this round I am using Cygwin, that is the only difference that I have done. -Pum
# 7  
Old 05-30-2015
So run it with bash instead of ksh.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Switching between directories and mkdir/copy dir/file

I was trying to copy the files inside the path /home/user/check/Q1/dir/folder1/expected/n/a1.out1 and a1.out2 and a1.out3 to /home/user/check/Q2/dir/folder1/expected/n/ if n directory is not present at Q2/dir/folder1/expected/ then directory should be created first. And, script follow the... (5 Replies)
Discussion started by: Mannu2525
5 Replies

2. UNIX for Advanced & Expert Users

Secure Copy - File Transfer between 2 server

Using RCP command we can transfer file from one server to another server. While transferring we can rename the file also e.g. File name = FILE123.txt (lying on Source server = oldserver) Target Server Name = newyour Renamed File = FILE456.txt rcp FILE123.txt newyour:./FILE456.txt... (1 Reply)
Discussion started by: Pash
1 Replies

3. Shell Programming and Scripting

Copy files and subdirs from dir to a new dir

Hello Comunity I am trying to make a bash shell script that it copies files and subdirs(with files) to a new dir. I would like the dest_dir to contain only subdirectories with files not other subdirs inside. it called : cpflatdir src_dir dest_dir Pleaze help me! Thank you in... (2 Replies)
Discussion started by: BTKBaaMMM
2 Replies

4. Shell Programming and Scripting

check if some file is in copy process, then transfer it

my user copy large files, and it's take 10min for file to be copied to the server (/tmp/user/ files/), if in the meantime start my scheduled script, then it will copy a part of some file to server1 my idea is to check the file size twice in a short period (1-2 seconds) of time, then compare, if... (5 Replies)
Discussion started by: waso
5 Replies

5. Shell Programming and Scripting

Copy files from input file with dir structure

hi, I want to copy files from source directory based on input file (or output of previous command) and i want to have the SAME DIRECTORY STRUCTURE. Note that i will have other files and directories which i dont want to copy to destination. For example, dir source has following content:... (22 Replies)
Discussion started by: dragon.1431
22 Replies

6. Shell Programming and Scripting

Copy Files to Dir and Check If File Exists

Hi everyone. I am trying to write a bash script that will copy files from one directory to another but I need to be able to check the directory that I'm copying the files to and see if the file already exists. If it does I need to add a number at the end of the copied file. Thanks for your help. (3 Replies)
Discussion started by: snag49ers
3 Replies

7. UNIX for Dummies Questions & Answers

Copy dir/file from one place to another.

Hello all. I'm not getting the hang of Paths. I have a dir w/files that I want to copy to another dir. Right now I am in the "source" directory. I want to copy it to Ch7. "cp -r source Ch7". Ch7 was already created. 1st msg.: cannot stat `source`: No such file or dir. I typed pwd & got... (3 Replies)
Discussion started by: Ccccc
3 Replies

8. UNIX for Dummies Questions & Answers

File Transfer issues SUN - > AIX

Hi, I'm puzzled at how this could be. I'm trying to transfer some files from an Sun box to an AIX box via FTP. The file transfer goes fine until it reaches a file of about 150k then times out and fails. The FTP Does not seem to be able to transfer files of more than 150k! However, I can... (5 Replies)
Discussion started by: bbbngowc
5 Replies

9. UNIX and Linux Applications

CPIO Problem, copy to the root dir / instead of current dir

HI all, I got a CPIO archive that contains a unix filesystem that I try to extract, but it extract to the root dir / unstead of current dir, and happily it detects my file are newer otherwise it would have overwrited my system's file! I tried all these commands cpio -i --make-directories <... (2 Replies)
Discussion started by: nekkro-kvlt
2 Replies

10. Shell Programming and Scripting

how to copy a file to a directory ,where file and dir are sent as args to a function?

Hi all, I wanted to know how i can copy a file to a directory and then verify if that file is completely copied or not? Now the issues here is that the dir and the source file are to be sent as arguments to a function( this function should actually copy the files to a dir, then check if its... (0 Replies)
Discussion started by: wrapster
0 Replies
Login or Register to Ask a Question