Removing a ? from multiple files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing a ? from multiple files
# 1  
Old 07-18-2018
Removing a ? from multiple files

Hi all,

I have about 1.8 million files in a directory structre, that contain a ? on the end, for example:

Code:
/testdocs/1/mar/08/08/images/user/{1234-1234-1234-1234}0?

Is there a way to go through the testdocs folder, recursively, and remove the ? from all docs that have one on the end?

Thanks!

Tirm
# 2  
Old 07-18-2018
Try
Code:
ls *\?
ls */*\?
find . -name "*\?"

# 3  
Old 07-18-2018
Quote:
Originally Posted by RudiC
Try
Code:
ls *\?
ls */*\?
find . -name "*\?"

Thanks RudiC, that will definitely locate the files, but what about the rename? The remove of the ? on the end?

Thanks!

Tirm
# 4  
Old 07-18-2018
Code:
for FN in *\?; do mv "$FN" "${FN%\?}"; done


etc ...
# 5  
Old 07-18-2018
Quote:
Originally Posted by RudiC
Code:
for FN in *\?; do mv "$FN" "${FN%\?}"; done


etc ...
I can't seem to get the right results with the for loop.

I got really close using:

Code:
find -name $'*\r*' -exec rename $'s|[\r]| |g' '{}' \;

This works for every character it seems EXCEPT for \r! \n works, any character works, but not \r. I'm not sure why.

Its driving me a bit nuts, this shouldnt be this difficult! Smilie

Just to add the ? is in fact a \r where the cp script was built using a windows c# program.

Last edited by tirmUK; 07-18-2018 at 09:32 AM.. Reason: Additional information
# 6  
Old 07-18-2018
What exactly is going wrong? Without precise error description, nobody will be able to help you.
# 7  
Old 07-18-2018
Here is the find working:

Code:
find -name $'*\r*'
./FDBCFEAE-021F-47BC-896B-A225C198C1A1{52730124-EF33-405F-9A8A-C840F5CEFB95}0?

Here is the command with the replace and the error message

Code:
find -name $'*\r*' -exec rename $'s|\r| |g' '{}' \;
rename: not enough arguments

What am I doing wrong in my exec command that might cause this?

Thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Removing characters from beginning of multiple files

Hi, I have been searching how to do this but I can't seem to find how to do it. Hopefully someone can help. I have multiplr files, 100's example 12345-zxys.213423.zyz.txt. I want to be able to take all these files and remove the first '12345-' from each of the files. '12345-' these characters... (5 Replies)
Discussion started by: israr75
5 Replies

2. Shell Programming and Scripting

Removing carriage returns from multiple lines in multiple files of different number of columns

Hello Gurus, I have a multiple pipe separated files which have records going over multiple Lines. End of line separator is \n and records going over multiple lines have <CR> as separator. below is example from one file. 1|ABC DEF|100|10 2|PQ RS T|200|20 3| UVWXYZ|300|30 4| GHIJKL|400|40... (7 Replies)
Discussion started by: dJHa
7 Replies

3. Shell Programming and Scripting

Removing multiple lines from input file, if multiple lines match a pattern.

GM, I have an issue at work, which requires a simple solution. But, after multiple attempts, I have not been able to hit on the code needed. I am assuming that sed, awk or even perl could do what I need. I have an application that adds extra blank page feeds, for multiple reports, when... (7 Replies)
Discussion started by: jxfish2
7 Replies

4. UNIX for Dummies Questions & Answers

Renaming Multiple Files by removing characters

Hi I would like to rename Multiple files in a Unix Directory using Ksh Command. Eg ATT8-2011-10-01 00:00:00-MSA-IMM-SINGLE_AND_FAMILY_COVERAGE-DED-$2000-X114817.PDF needs to be renamed as ATT8-2011-10-01-MSA-IMM-SINGLE_AND_FAMILY_COVERAGE-DED-$2000-X114817.PDF Basically the time... (2 Replies)
Discussion started by: pchegoor
2 Replies

5. UNIX for Dummies Questions & Answers

Removing Lines Shared by Multiple Files

Hey everyone, I have a question about comparing two files. I have two lists of files. The first list, todo.csv, lists a series of compounds my supervisor wants me to perform calculations on. The second list, done.csv, lists a series of compounds that I have already performed calculations on.... (2 Replies)
Discussion started by: Stuart Ness
2 Replies

6. Shell Programming and Scripting

Removing matching text from multiple files with a shell script

Hello all, I am in need of assistance in creating a script that will remove a specified block of text from multiple .htaccess files. (roughly 1000 files) I am attempting to help with a project to clean up a linux server that has a series of unwanted url rewrites in place, as well as some... (4 Replies)
Discussion started by: boxx
4 Replies

7. Shell Programming and Scripting

PERL: removing blank lines from multiple files

Hi Guru's , I have a whole bunch of files in /var/tmp that i need to strip any blank lines from, so ive written the following script to identify the lines (which works perfectly).. but i wanted to know, how can I actually strip the identified lines from the actual source files ?? my... (11 Replies)
Discussion started by: hcclnoodles
11 Replies

8. UNIX for Dummies Questions & Answers

Removing prefix from multiple files and renaming file extension

Hello i have the files in this format pdb1i0t.ent pdb1lv7.ent pdb1pp6.ent pdb1tj2.ent pdb1xg2.ent pdb2b4b.ent pdb2ewe.ent Now i have to remove the prefix pdb from all the files and also i need to change the extension of .ent to .txt The new file should look like this ... (3 Replies)
Discussion started by: empyrean
3 Replies

9. Shell Programming and Scripting

removing non-printable chars from multiple files

How do I remove non-printable characters from all txt files and output the results to one file? I've tried the following: tr -cd '\n' < *.txt > out.txt and it gives ambiguous redirect error. How can I get it to operate on all txt files in the current directory and append the output to... (1 Reply)
Discussion started by: revax
1 Replies

10. Shell Programming and Scripting

Removing M^ from multiple files

to do this i usually type dos2unix <file> -o <file> and this will remove the M^ from the end of each file. well i have over 100 files that someone copied that i need. how do i remove the M^. i saw a perl script but i am not familiar with .pl at all really (7 Replies)
Discussion started by: deaconf19
7 Replies
Login or Register to Ask a Question