Need help in finding and copying list of files using bash shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help in finding and copying list of files using bash shell script
# 8  
Old 09-14-2014
to delete the ?:

Code:
awk '/ /{f=$0; sub("\\?| ",x);system("mv \""f "\" "$0)}' file

# 9  
Old 09-14-2014
Still not working... Smilie
attached a screen shot of case dir.
May be it will help to figure out the problem :-|

when I list in corresponding directory
Code:
/home/linuxUser/case/files/testRename/pbar?.stl 
/home/linuxUser/case/files/testRename/tk?.stl 
/home/linuxUser/case/files/testRename/mbyv?.stl 
/home/linuxUser/case/files/testRename/mvFiles 
/home/linuxUser/case/files/testRename/vm3?.stl 
/home/linuxUser/case/files/testRename/mk?.stl

Need help in finding and copying list of files using bash shell script-screenshot-2014-09-15-00-09-38png

Last edited by linuxUser_; 09-14-2014 at 03:46 PM..
# 10  
Old 09-15-2014
What is the output from the command:
Code:
ls | od -bc

when you are in this directory?
This User Gave Thanks to Don Cragun For This Post:
# 11  
Old 09-15-2014
Quote:
Originally Posted by Don Cragun
What is the output from the command:
Code:
ls | od -bc

when you are in this directory?
Dear Don Cragun,

Output for the command you provided from that directory
Code:
0000000 155 142 171 166 015 056 164 170 164 012 155 153 015 056 164 170
          m   b   y   v  \r   .   t   x   t  \n   m   k  \r   .   t   x
0000020 164 012 155 166 106 151 154 145 163 012 160 142 141 162 015 056
          t  \n   m   v   F   i   l   e   s  \n   p   b   a   r  \r   .
0000040 164 170 164 012 164 153 015 056 164 170 164 012 166 155 063 015
          t   x   t  \n   t   k  \r   .   t   x   t  \n   v   m   3  \r
0000060 056 164 170 164 012
          .   t   x   t  \n
0000065

By the way what is od and -bc?

Thanks & Regards,
linuxUser_

Last edited by linuxUser_; 09-15-2014 at 01:23 AM..
# 12  
Old 09-15-2014
This should rename your files for you:
Code:
ls|awk '
/\r/ {  new = $0
        gsub(/\r/, "", new)
        printf("mv \"%s\" \"%s\"\n", $0, new)
}' | sh

If you want to do this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk, /usr/xpg6/bin/awk, or nawk.

If you want to see what it will do before actually moving the files, delete the | sh from the end of the script, but don't expect what shows up on the terminal to look right; the carriage returns in the current filenames will make it look like the mv and the start of the old filename have been overwritten by the remainder of the old filename followed by the corrected filename.

Last edited by Don Cragun; 09-15-2014 at 02:30 AM.. Reason: Fix typo male => make.
This User Gave Thanks to Don Cragun For This Post:
# 13  
Old 09-15-2014
Quote:
Originally Posted by Don Cragun
This should rename your files for you:
Code:
ls|awk '
/\r/ {  new = $0
        gsub(/\r/, "", new)
        printf("mv \"%s\" \"%s\"\n", $0, new)
}' | sh

If you want to do this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk, /usr/xpg6/bin/awk, or nawk.

If you want to see what it will do before actually moving the files, delete the | sh from the end of the script, but don't expect what shows up on the terminal to look right; the carriage returns in the current filenames will male it look like the mv and the start of the old filename have been overwritten by the remaindeer of the old filename followed by the corrected filename.
Dear Don Cragun,

Thanks is really a small word but still really I thankful to you. Smilie
# 14  
Old 09-15-2014
Quote:
Originally Posted by linuxUser_
. . .
By the way what is od and -bc?
. . .
od (octal dump?) is a command to "dump files in octal and other formats " (cf man od)
Quote:
-b same as -t o1, select octal bytes
-c same as -t c, select ASCII characters or backslash escapes
This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copying the files in to multiple location using shell script

Hi All, i'm trying to copy the 1.txt files (sample files) in to different path location using the below command. But it is not copying the files , when i tried for single location able to copy the file. can any one please assist here. Please find the below path :- /ckr_mkr1/licencekey... (2 Replies)
Discussion started by: venkat918
2 Replies

2. Shell Programming and Scripting

Copying large files in a bash script stops execution

Hello, I'm new to this forum and like to first of all say hello to everyone. I've got a really annoying problem at the moment. I'm trying to rsync some files (about 200MB with one file of 120MB) from a Raspberry PI with raspbian to a debian server via rsync. This procedure is stored in a... (3 Replies)
Discussion started by: wex_storm
3 Replies

3. Shell Programming and Scripting

Help with copying files using shell script

I want to write a shell script to copy a list of files from one directory to another. And while copying it should change the first character of the filename to uppercase and others to lowercase.Below is what i have tried so far. for file in "$@" do if then ufile=`echo $file | sed... (5 Replies)
Discussion started by: vishal.desai
5 Replies

4. Shell Programming and Scripting

Files copying - [ Listed files alone. ] - Shell script

Hi All, I am doing this for svn patch making. I got the list of files to make the patch. I have the list in a file with path of all the files. To Do From Directory : /myproject/MainDir To Directory : /myproject/data List of files need to copy is in the file: /myproject/filesList.txt ... (4 Replies)
Discussion started by: linuxadmin
4 Replies

5. Shell Programming and Scripting

Finding & Copying files

Hello :) can someone please help me with this task: I am in the shell, in folder "Main" below the folder Main are sub folders: "sourceA", "Source B", and "target" in sourceA and source B are files, and in folder "Main" is a textfile, with filenames, one filename per line. I need a... (4 Replies)
Discussion started by: Y-T
4 Replies

6. Shell Programming and Scripting

Shell script for copying files from 1 server to other

Hi, I just need a shell script that copies a list of files from a directory in a remote server to my current directory at local server the remote server may contain the following list: /root/pradeep/myfiles/default /root/pradeep/myfiles/dir1 /root/pradeep/myfiles/dir2 ...... (1 Reply)
Discussion started by: paddu
1 Replies

7. Shell Programming and Scripting

Shell Script to connect to another server and copying files

Hi Unix Gurus, I have a doubt reg file transfer. I have used the below script to connect to another server and find files having modified for the last 24 hours and have to move the file to another server. While i tried i am getting authentication failed, destination path not found issue. ... (2 Replies)
Discussion started by: incepted
2 Replies

8. Shell Programming and Scripting

script for Finding files in a folder and copying to another folder

Hi all, I have a folder '/samplefolder' in which i have some files like data0.txt, data1.txt and data2.txt. I have to search the folder for existence of the file data0.txt first and if found have to copy it to some other file; next i have to search the folder for existence of file... (5 Replies)
Discussion started by: satish2712
5 Replies

9. UNIX for Dummies Questions & Answers

finding and copying files !

Hi , I have a question relating to finding and copying files. i need to find the .pdf files from the specified directory which has subdirectories too. I only need .pdf files and not the directories and need to copy those files into my current directory. copy files from :... (5 Replies)
Discussion started by: bregoty
5 Replies

10. Shell Programming and Scripting

copying files and Renaming them + shell script

Hi, I have a problem. I have some text files in a folder. The names can be like: emp.txt emp1.txt emp3.txt 32emp4.txt What i need is i have to copy all the files which have "emp" string in their filename to a different folder and those file names... (7 Replies)
Discussion started by: pathanjalireddy
7 Replies
Login or Register to Ask a Question