Removing a ? from multiple files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing a ? from multiple files
# 8  
Old 07-18-2018
Can't speak for rename. Try to execute with the -x (xtrace) option set.

How about

Code:
find -name $'*\r*' | while read FN; do echo mv "$FN" "${FN%?}"; done

# 9  
Old 07-18-2018
That didnt work RudiC:

FileName:
Code:
FDBCFEAE-021F-47BC-896B-A225C198C1A1{52730124-EF33-405F-9A8A-C840F5CEFB95}0?

Command and result:

Code:
find -name $'*\r*' | while read FN; do echo mv "$FN" "${FN%?}"; done
 ./FDBCFEAE-021F-47BC-896B-A225C198C1A1{52730124-EF33-405F-9A8A-C840F5CEFB95}0}0

No change to the file.
# 10  
Old 07-18-2018
That echo is for check / debug purposes; it displays what the commands had looked like when executed. I should have mentioned that. As you can see in the output, the <CR> (\r) character makes the target file name overwrite the mv command.

- pipe above through less for checking.
- Remove the echo and rerun.
This User Gave Thanks to RudiC For This Post:
# 11  
Old 07-19-2018
Please try below command. It renames all files in directory/subdirectories.


Code:
 find . -type f -name "*?" | while read file; do mv "$file" "${file%?}"; done

# 12  
Old 07-19-2018
Quote:
Originally Posted by chandan.chaman
Please try below command. It renames all files in directory/subdirectories.


Code:
 find . -type f -name "*?" | while read file; do mv "$file" "${file%?}"; done

Hi Chandan,

Unfortunately, it removes the last character from the file, no matter what it is, not just the carraige return.

---------- Post updated at 11:06 AM ---------- Previous update was at 10:58 AM ----------

Quote:
Originally Posted by RudiC
That echo is for check / debug purposes; it displays what the commands had looked like when executed. I should have mentioned that. As you can see in the output, the <CR> (\r) character makes the target file name overwrite the mv command.

- pipe above through less for checking.
- Remove the echo and rerun.
Hi RubiC, that worked a treat, thank you for your help, and your patience as I tried to explain the issue!
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