Sponsored Content
Top Forums UNIX for Advanced & Expert Users File name contains escape character--how to fix? Post 302993857 by drysdalk on Wednesday 15th of March 2017 12:07:18 PM
Old 03-15-2017
Hi,

The inode thing is exactly what I've always done in this situtation. But I just thought I'd have a play about and see if I could find another answer, and there's this approach too (which might be handier if you need to script this on a regular basis, for some really weird reason).

On up-to-date Bash on modern Linux, you can use a regex like this:

[^[:print:]]

to match non-printable characters only. I created a file with the same name as yours, and some other besides, and here's a sample session showing that regex in action.

Code:
$ ls -lb
total 0
-rw-rw-r-- 1 unixforum unixforum 0 Mar 15 16:03 Right
-rw-rw-r-- 1 unixforum unixforum 0 Mar 15 15:58 Wrong\033[D\033[D\033[D\033[D\033[DRight
-rw-rw-r-- 1 unixforum unixforum 0 Mar 15 16:02 Wrong\ Filename.csv
-rw-rw-r-- 1 unixforum unixforum 0 Mar 15 16:03 Wrongness
-rw-rw-r-- 1 unixforum unixforum 0 Mar 15 16:02 Wrong.txt
$ ls Wrong[^[:print:]]*
Wrong?[D?[D?[D?[D?[DRight
$ rm -v Wrong[^[:print:]]*
removed 'Wrong'$'\033''[D'$'\033''[D'$'\033''[D'$'\033''[D'$'\033''[DRight'
$ ls -l
total 0
-rw-rw-r-- 1 unixforum unixforum 0 Mar 15 16:03 Right
-rw-rw-r-- 1 unixforum unixforum 0 Mar 15 16:02 Wrong Filename.csv
-rw-rw-r-- 1 unixforum unixforum 0 Mar 15 16:03 Wrongness
-rw-rw-r-- 1 unixforum unixforum 0 Mar 15 16:02 Wrong.txt
$

So if you absolutely needed to automate the removal of such things, this might be a useful approach if your shell and/or distro support it.
This User Gave Thanks to drysdalk For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Escape character in vi?

I want to replace a string which contains "/" in vi but what is the escape character for forward slash? e.g. I have a text file with the contents below and I want to replace "/Top/Sub/Sub1" with "ABC". /Top/Sub/Sub1 The replace command I am using is ... (4 Replies)
Discussion started by: stevefox
4 Replies

2. Shell Programming and Scripting

awk / escape character

Hi I'm trying to split a dir listing eg /home/foo1/foo2 I'm using ksh I've tried dir=/home/foo1/foo2 splitit=`echo $dir | awk -F '\/' '{print $1}'` echo $splitit nothing is output! I have checked the escape character. The only one I have found is \ BTW `pwd` | awk -F \/... (8 Replies)
Discussion started by: OFFSIHR
8 Replies

3. Shell Programming and Scripting

Escape character

Hi , I want to change space to ' in my script. I tried doing this, sed 's/ /\'/g' filename but i could not get it. can some one help me please. Thanks, Deepak (4 Replies)
Discussion started by: deepakpv
4 Replies

4. Shell Programming and Scripting

escape character in tcsh

Hello, I wanted to display command with echo like this in tcsh. output should be "//'test.test1.test2'" (" at both ends also required in output) Please help me. (1 Reply)
Discussion started by: balareddy
1 Replies

5. Shell Programming and Scripting

Escape character - sed

Hi All, How do i write in sed for the 6th and 7th field of etc/passwd file as it involves "/" character? Does mine below is correct? It's incomplete script as i need help with syntax as i always getting may errors :( Example of etc/passwd file: blah:x:1055:600:blah... (6 Replies)
Discussion started by: c00kie88
6 Replies

6. Shell Programming and Scripting

awk escape character

ll|awk '{print "INSERT INTO SCHEMA.TABLE_NAME VALUES (`"$9 "`,"$5");" }' INSERT INTO SCHEMA.TABLE_NAME VALUES (``,); INSERT INTO SCHEMA.TABLE_NAME VALUES (`TABLE_PARTITION_Y2010M03D06.dmp`,7923328); INSERT INTO SCHEMA.TABLE_NAME VALUES (`TABLE_PARTITION_Y2010M03D06.log`,1389); But I want ' in... (2 Replies)
Discussion started by: faruque.ahmed
2 Replies

7. Shell Programming and Scripting

replace \ (escape character)

All , i have input line as below . abc\ , ewioweioi \, and want the output as below removing the "\" abc , ewioweioi , could anyone help me out (2 Replies)
Discussion started by: expert
2 Replies

8. Shell Programming and Scripting

sed - with escape character

i have string as below str=".<date>" in which i need to replace < with /< , when i tried with sed , got the output. --> echo $str | sed 's/</\\</g' .\<date> when i tried to assign it to a variable , i am not getting the same --> a=`echo $str | sed 's/</\\</g'` ; echo $a... (4 Replies)
Discussion started by: expert
4 Replies

9. Shell Programming and Scripting

ksh escape a character

friends, I have a situation where i am using a $RANDOM function along with the filename, I want this to be escaped by the OS in the first assignment (works as expected) and executed in the second assignment (does not execute $RANDOM) filename1=filename1_\$RANDOM echo $filename1... (3 Replies)
Discussion started by: Balaji M
3 Replies

10. Shell Programming and Scripting

Function to add escape character before specified character

Hi , I am looking for a function which will do the following. 1. I have a variable which will hold few special chracter like SPECIAL_CHARS="& ;"2. I have an escape character. ESCAPE_CHAR="\"3. Now when I passed some string in the function it will return the same string but now it will... (8 Replies)
Discussion started by: Anupam_Halder
8 Replies
HXUNENT(1)							  HTML-XML-utils							HXUNENT(1)

NAME
hxunent - replace HTML predefined character entities by UTF-8 SYNOPSIS
hxunent [ -b ] [ -f ] [ file ] DESCRIPTION
The hxunent command reads the file (or standard input) and copies it to standard output with &-entities by their equivalent character (encoded as UTF-8). E.g., &quot; is replaced by " and &lt; is replaced by <. OPTIONS
The following options are supported: -b The five builtin entities of XML (&lt; &gt; &quot; &apos; &amp;) are not replaced but copied unchanged. This is necessary if the output has to be valid XML or SGML. -f This option changes how unknown entities or lone ampersands are handled. Normally they are copied unchanged, but this option tries to "fix" them by replacing ampersands by &amp;. Often such stray ampersands are the result of copy and paste of URLs into a document and then this option indeed fixes them and makes the document valid. DIAGNOSTICS
The program's exit value is 0 if all went well, otherwise: 1 The input couldn't be read (file not found, file not readable...) 2 Wrong command line arguments. SEE ALSO
asc2xml(1), xml2asc(1), UTF-8 (RFC 2279) BUGS
The program assumes entities are as defined by HTML. It doesn't read a document's DTD to find the actual definitions in use in a document. With -f, it will even remove all entities that are not HTML entities. 6.x 10 Jul 2011 HXUNENT(1)
All times are GMT -4. The time now is 04:25 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy