|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Find and replace mulitple charaters in filenames
I have a virtual pdf printer set up on my server which produces files with the following prefix: Code:
smbprn_00000044_Microsoft_Word_-_OriginalFilename.pdf the number in the center of the file increase by one for each new file. I want to remove all the charaters infront of OriginalFilename.pdf using the following code: Code:
find . -type f -name '*[:smbprn_*_Microsoft_Word_-_*.pdf"]*' | while IFS= read -r; do mv -- "$REPLY" "${REPLY//[:smbprn_*_Microsoft_Word_-_*.pdf\"]}" done;which I modified form here If I run this directly from the command prompt I simply end up with a second > prompt? I think I must be pretty close, any help would be welcome |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Try: Code:
find . -type f -name 'smbprn_*_Microsoft_Word_-_*.pdf' | while read -r; do echo mv -- "$REPLY" "${REPLY/smbprn_*_Microsoft_Word_-_/}"; done;Remove the echo when the command lines look OK. And, I hope your original filename will not have _Microsoft_Word_-_ or smbprn_ . You may also do this with find itself using -exec (with some assumptions). |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Code:
find . -type f -name '*[:smbprn_*_Microsoft_Word_-_*.pdf"]*' | while IFS= read -r; do mv -- "$REPLY" "${REPLY//[:smbprn_*_Microsoft_Word_-_*.pdf\"]}" ;done;Last edited by Scrutinizer; 01-19-2013 at 08:37 AM.. Reason: code tags |
|
#4
|
|||
|
|||
|
Thanks for the replies; This code: Code:
find . -type f -name '*[:smbprn_*_Microsoft_Word_-_*.pdf"]*' | while IFS= read -r; do mv -- "$REPLY" "${REPLY//[:smbprn_*_Microsoft_Word_-_*.pdf\"]}" ;done;Gives this result: Code:
$ find . -type f -name '*[:smbprn_*_Microsoft_Word_-_*.pdf"]*' | while IFS= read -r; do mv -- "$REPLY" "${REPLY//[:smbprn_*_Microsoft_Word_-_*.pdf\"]}" ;done;
mv: cannot open `./smbprn_00000046_Microsoft_Word_-_Letters2.pdf' for reading: Permission denied
mv: cannot create regular file `/TePage': Permission denied
mv: cannot open `./smbprn_00000045_Microsoft_Word_-_Letters1.pdf' for reading: Permission deniedI get the same result even if run as root, the user I am running the command with has read/write permissions This code: Code:
find . -type f -name 'smbprn_*_Microsoft_Word_-_*.pdf' | while read -r; do echo mv -- "$REPLY" "${REPLY/smbprn_*_Microsoft_Word_-_/}"; done;Does move the files, but I'm not sure where to and the original file are still there: Code:
find . -type f -name 'smbprn_*_Microsoft_Word_-_*.pdf' | while read -r; do echo mv -- "$REPLY" "${REPLY/smbprn_*_Microsoft_Word_-_/}"; done;
mv -- ./smbprn_00000046_Microsoft_Word_-_Letters2.pdf ./Letters2.pdf
mv -- ./smbprn_00000045_Microsoft_Word_-_Letters1.pdf ./Letters1.pdfbut then: Code:
$ ls smbprn_00000045_Microsoft_Word_-_Letters1.pdf Test_Page.pdf smbprn_00000046_Microsoft_Word_-_Letters2.pdf I am running these commands from within the directory containing the files |
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
Hey, I told you to remove the echo.
I was echo'ing the mv command lines so that you could know what is being moved... |
| The Following User Says Thank You to elixir_sinari For This Useful Post: | ||
barrydocks (01-19-2013) | ||
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
Quote:
Just out of interest what would be the easiest way to append the file date to the filename for these files? Thanks |
| Sponsored Links | |
|
|
#7
|
||||
|
||||
|
How do you mean? Please elaborate with an example.
|
| Sponsored Links | ||
|
![]() |
| Tags |
| filename, multiple characters, remove |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| replace word with special charaters | drtabc | UNIX for Advanced & Expert Users | 4 | 02-23-2010 11:56 PM |
| Help with Find/Replace Javascript Injected Strings in mulitple files | zzlegs | Shell Programming and Scripting | 1 | 05-28-2009 07:29 PM |
| feeding filenames to find command | sanjay1979 | Solaris | 4 | 03-31-2009 05:43 PM |
| find filenames like unix commands | deepakgang | Shell Programming and Scripting | 6 | 06-29-2008 11:41 PM |
| find lowercase filenames | jpprial | UNIX for Dummies Questions & Answers | 4 | 01-28-2002 03:57 PM |
|
|