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
# 8  
Old 05-31-2015
it has progress but there were still errors in cygwin, i think cygwin is the issue here
i changed the code a little bit:
Code:
#!/bin/ksh
dir1="/home/pumela/pumela"
cd "$dir1"
for srcd in /home/user/pumela/
do    targetd=${srcd#*/}
    if [ ! -d "$srcd" ] || [ ! -d "$targetd" ]
    then    continue    # Source or target directory does not exist.
    fi
    cd "$srcd" > /home/pumela/pumela/archive
    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 - > /home/pumela/pumela/archive
done

then i tried running it , i first do a pwd and ls
Code:
pumela@vampyrtest Non Production
$ pwd
/home/pumela/pumela

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

pumela@vampyrtest Non Production ~/pumela
$ bash pumelatxf.ksh
: No such file or directory/home/pumela/pumela
pumelatxf.ksh: line 18: syntax error near unexpected token `done'
pumelatxf.ksh: line 18: `done'

pumela@vampyrtest Non Production
$ bash pumelatxf.ksh
: No such file or directory/home/pumela/pumela
pumelatxf.ksh: line 18: syntax error near unexpected token `done'
pumelatxf.ksh: line 18: `done'

pumela@vampyrtest Non Production
$


Last edited by phumaree; 05-31-2015 at 01:21 PM..
# 9  
Old 05-31-2015
What editor did you use when you modified this script to run on Widows? You might get output like this if some of the lines in the script are terminated by <carriage-return><newline> character pairs instead of the UNIX <newline> line terminators (without the <carriage-return>s)...

Show us the output from the command:
Code:
od -bc < pumelatxf.ksh

If you see \r as well as \n in that output, try running the command:
Code:
tr -d '\r' < pumelatxf.ksh > xyzzy && cp xyzzy pumelatxf.ksh && rm xyzzy

and, if that succeeds, try running it again with:
Code:
bash -xv pumelatxf.ksh

and show us the output that produces.
# 10  
Old 05-31-2015
Quote:
Originally Posted by Don Cragun
What editor did you use when you modified this script to run on Widows? You might get output like this if some of the lines in the script are terminated by <carriage-return><newline> character pairs instead of the UNIX <newline> line terminators (without the <carriage-return>s)...

Show us the output from the command:
Code:
od -bc < pumelatxf.ksh

If you see \r as well as \n in that output, try running the command:
Code:
tr -d '\r' < pumelatxf.ksh > xyzzy && cp xyzzy pumelatxf.ksh && rm xyzzy

and, if that succeeds, try running it again with:
Code:
bash -xv pumelatxf.ksh

and show us the output that produces.
hi Don, here were the outputs (i am using crimson editor):
Code:
pumela@vampyrtest Non Production ~/pumela
$ od -bc < pumelatxf.ksh
0000000 043 041 057 142 151 156 057 153 163 150 012 144 151 162 061 075
          #   !   /   b   i   n   /   k   s   h  \n   d   i   r   1   =
0000020 042 057 150 157 155 145 057 165 163 145 162 057 160 165 155 145
          "   /   h   o   m   e   /   u   s   e   r   /   p   u   m   e
0000040 154 141 042 012 143 144 040 042 044 144 151 162 061 042 012 146
          l   a   "  \n   c   d       "   $   d   i   r   1   "  \n   f
0000060 157 162 040 163 162 143 144 040 151 156 040 057 150 157 155 145
          o   r       s   r   c   d       i   n       /   h   o   m   e
0000100 057 165 163 145 162 057 160 165 155 145 154 141 057 012 144 157
          /   u   s   e   r   /   p   u   m   e   l   a   /  \n   d   o
0000120 040 040 040 040 164 141 162 147 145 164 144 075 044 173 163 162
                          t   a   r   g   e   t   d   =   $   {   s   r
0000140 143 144 043 052 057 175 012 040 040 040 040 151 146 040 133 040
          c   d   #   *   /   }  \n                   i   f       [
0000160 041 040 055 144 040 042 044 163 162 143 144 042 040 135 040 174
          !       -   d       "   $   s   r   c   d   "       ]       |
0000200 174 040 133 040 041 040 055 144 040 042 044 164 141 162 147 145
          |       [       !       -   d       "   $   t   a   r   g   e
0000220 164 144 042 040 135 012 040 040 040 040 164 150 145 156 040 040
          t   d   "       ]  \n                   t   h   e   n
0000240 040 040 143 157 156 164 151 156 165 145 040 040 040 040 043 040
                  c   o   n   t   i   n   u   e                   #
0000260 123 157 165 162 143 145 040 157 162 040 164 141 162 147 145 164
          S   o   u   r   c   e       o   r       t   a   r   g   e   t
0000300 040 144 151 162 145 143 164 157 162 171 040 144 157 145 163 040
              d   i   r   e   c   t   o   r   y       d   o   e   s
0000320 156 157 164 040 145 170 151 163 164 056 012 040 040 040 040 146
          n   o   t       e   x   i   s   t   .  \n                   f
0000340 151 012 040 040 040 040 143 144 040 042 044 163 162 143 144 042
          i  \n                   c   d       "   $   s   r   c   d   "
0000360 040 076 040 057 150 157 155 145 057 165 163 145 162 057 160 165
              >       /   h   o   m   e   /   u   s   e   r   /   p   u
0000400 155 145 154 141 057 141 162 143 150 151 166 145 012 040 040 040
          m   e   l   a   /   a   r   c   h   i   v   e  \n
0000420 040 146 157 162 040 146 151 154 145 040 151 156 040 052 056 143
              f   o   r       f   i   l   e       i   n       *   .   c
0000440 163 166 012 040 040 040 040 144 157 040 040 040 040 151 146 040
          s   v  \n                   d   o                   i   f
0000460 133 040 042 044 146 151 154 145 042 040 075 040 047 052 056 143
          [       "   $   f   i   l   e   "       =       '   *   .   c
0000500 163 166 047 040 135 012 040 040 040 040 040 040 040 040 164 150
          s   v   '       ]  \n                                   t   h
0000520 145 156 040 040 040 040 142 162 145 141 153 040 040 040 040 043
          e   n                   b   r   e   a   k                   #
0000540 040 116 157 040 052 056 143 163 166 040 146 151 154 145 163 040
              N   o       *   .   c   s   v       f   i   l   e   s
0000560 164 157 040 155 157 166 145 040 151 156 040 164 150 151 163 040
          t   o       m   o   v   e       i   n       t   h   i   s
0000600 144 151 162 145 143 164 157 162 171 012 040 040 040 040 040 040
          d   i   r   e   c   t   o   r   y  \n
0000620 040 040 145 154 163 145 040 040 040 040 145 143 150 157 040 155
                  e   l   s   e                   e   c   h   o       m
0000640 166 040 052 056 143 163 166 040 042 044 144 151 162 061 057 044
          v       *   .   c   s   v       "   $   d   i   r   1   /   $
0000660 164 141 162 147 145 164 144 042 040 040 040 040 043 040 115 157
          t   a   r   g   e   t   d   "                   #       M   o
0000700 166 145 040 164 150 145 040 146 151 154 145 163 012 040 040 040
          v   e       t   h   e       f   i   l   e   s  \n
0000720 040 040 040 040 040 040 040 040 040 142 162 145 141 153 012 040
                                              b   r   e   a   k  \n
0000740 040 040 040 040 040 040 040 146 151 012 040 040 040 040 144 157
                                      f   i  \n                   d   o
0000760 156 145 012 040 040 040 040 143 144 040 055 040 076 040 057 150
          n   e  \n                   c   d       -       >       /   h
0001000 157 155 145 057 165 163 145 162 057 160 165 155 145 154 141 057
          o   m   e   /   u   s   e   r   /   p   u   m   e   l   a   /
0001020 141 162 143 150 151 166 145 012 144 157 156 145
          a   r   c   h   i   v   e  \n   d   o   n   e
0001034

Code:
pumela@vampyrtest Non Production ~/pumela
$ tr -d '\r' < pumelatxf.ksh > xyzzy && cp xyzzy pumelatxf.ksh && rm xyzzy

Code:
pumela@vampyrtest Non Production ~/pumela
$ bash -xv pumelatxf.ksh
#!/bin/ksh
dir1="/home/user/pumela"
+ dir1=/home/user/pumela
cd "$dir1"
+ cd /home/user/pumela
for srcd in /home/user/pumela/
do    targetd=${srcd#*/}
    if [ ! -d "$srcd" ] || [ ! -d "$targetd" ]
    then    continue    # Source or target directory does not exist.
    fi
    cd "$srcd" > /home/user/pumela/archive
    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 - > /home/user/pumela/archive
done
+ for srcd in /home/user/pumela/
+ targetd=home/user/pumela/
+ '[' '!' -d /home/user/pumela/ ']'
+ '[' '!' -d home/user/pumela/ ']'
+ continue

pumela@vampyrtest Non Production ~/pumela
$


Last edited by phumaree; 05-31-2015 at 10:39 AM.. Reason: to add editor name
# 11  
Old 05-31-2015
I apologize. I assumed that you had read through the thread that you copied my code from: Moving files from parent path to multiple child path using bash in efficient way and that you were trying to do something similar, but copying CSV files instead of TXT files. What that thread was doing was to move files from one place in a file hierarchy up one level (removing one intermediate directory in the source path) to another set of pre-existing directories in that same source file hierarchy.

With your latest set of changes to my script, you are apparently trying to move files from /home/user/pumela to /home/user/pumela/home/user/pumela and, since /home/user/pumela/home/user/pumela is not an existing directory, the script exits because there is nothing to do. And, whereas in post #1 in this thread /home/user/pumela/archive was a target directory; in this latest set of changes to the script, it is some kind of regular file that stores the output produced by the most recently run cd command???

So, let's go back to step 1! Please forget about the script that you copied and tell us exactly what you are trying to do:
  1. What directory or directories contain files that you want to move?
  2. To what directory or directories do you want to move those files?
  3. Are the files you want to move on the same system as the directory or directories to which you want to move them?
  4. Is or are the target directory or directories on the same filesystem as the directory or directories that contain the files your want to move?
  5. Is cygwin (running under some version of Windows) the only system on which you want to run this script? If not, what other systems will you be using to run this script?

PS The title of this thread is "Issues in Csv file transfer copy from one dir to another". "Move" and "transfer copy" are two different things. Do you want to move files or do you want to copy files?

Last edited by Don Cragun; 05-31-2015 at 08:44 PM.. Reason: Add PS.
# 12  
Old 06-01-2015
I apologize also to this instance, I'm actually a bit new with the unix syntax
Quote:
Originally Posted by Don Cragun
I apologize. I assumed that you had read through the thread that you copied my code from: Moving files from parent path to multiple child path using bash in efficient way and that you were trying to do something similar, but copying CSV files instead of TXT files. What that thread was doing was to move files from one place in a file hierarchy up one level (removing one intermediate directory in the source path) to another set of pre-existing directories in that same source file hierarchy.

With your latest set of changes to my script, you are apparently trying to move files from /home/user/pumela to /home/user/pumela/home/user/pumela and, since /home/user/pumela/home/user/pumela is not an existing directory, the script exits because there is nothing to do. And, whereas in post #1 in this thread /home/user/pumela/archive was a target directory; in this latest set of changes to the script, it is some kind of regular file that stores the output produced by the most recently run cd command???

So, let's go back to step 1! Please forget about the script that you copied and tell us exactly what you are trying to do:
  1. What directory or directories contain files that you want to move? so in home/user/pumela there are csv files, my original plan is to put them in archive folder inside */pumela and my original plan is to acually tar them(convert the csv file into tar file, i'll study taring files later) in to 5 parts in that dir(archive)
  2. To what directory or directories do you want to move those files? in archive folder inside /home/user/pumela
  3. Are the files you want to move on the same system as the directory or directories to which you want to move them?yes
  4. Is or are the target directory or directories on the same filesystem as the directory or directories that contain the files your want to move?you're giving me a hard time in understanding this question, :P, add me on fb, pumelayurika@yahoo.com, phumfang, but i think YES Smilie
  5. Is cygwin (running under some version of Windows) the only system on which you want to run this script? If not, what other systems will you be using to run this script? telnet

PS The title of this thread is "Issues in Csv file transfer copy from one dir to another". "Move" and "transfer copy" are two different things. Do you want to move files or do you want to copy files?

Last edited by phumaree; 06-01-2015 at 11:39 AM..
# 13  
Old 06-01-2015
This is a MUCH simpler problem than the problem the script you copied was trying to solve. To move a bunch of files from a single directory to a subdirectory of that same directory, all you need is something like:
Code:
cd /home/user/pumela
mv *.csv archive

You didn't answer whether you want to move files or copy files. The above code moves files; if you want to copy them instead, change mv to cp. If you want to make hard links to the files (giving each of the files two names) instead of moving them or copying them; change mv to ln.

I asked what systems other than cygwin running on Windows you wanted this script to work on. You said telnet, but telnet is a utility implementing a communications protocol to a remote system; it is not a type of system like Windows, UNIX, or Linux.
# 14  
Old 06-02-2015
Thank you so much!
Quote:
Originally Posted by Don Cragun
This is a MUCH simpler problem than the problem the script you copied was trying to solve. To move a bunch of files from a single directory to a subdirectory of that same directory, all you need is something like:
Code:
cd /home/user/pumela
mv *.csv archive

You didn't answer whether you want to move files or copy files. The above code moves files; if you want to copy them instead, change mv to cp. If you want to make hard links to the files (giving each of the files two names) instead of moving them or copying them; change mv to ln.

I asked what systems other than cygwin running on Windows you wanted this script to work on. You said telnet, but telnet is a utility implementing a communications protocol to a remote system; it is not a type of system like Windows, UNIX, or Linux. - oh i only use windows OS
 
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