[comp.unix.questions] Need help reading a file with unusual name

onymouse@netcom.UUCP (John DeBert) (04/14/89)

I cannot access files with filenames containing "non-graphic" characters.
(How they got that way, I don't know.) I have two files that I need to
access called "maps\033w" (ls shows the name as "maps") but if I enter the
name as shown, I still cannot access it. I also have a file of substantial
size which has the CR character as it's filename. 

My books do not cover how to handle files with such names. 

How do I access these files, i.e., to read or rename? 

J DeBert
onymouse@netcom.UUCP 
"...anything you say can and will offend someone..." Lazarus Long 

ram@tslanpar.UUCP (ram) (04/18/89)

In article <579@netcom.UUCP>, onymouse@netcom.UUCP (John DeBert) writes:
> I cannot access files with filenames containing "non-graphic" characters.
> (How they got that way, I don't know.) I have two files that I need to
> access called "maps\033w" (ls shows the name as "maps") but if I enter the
> name as shown, I still cannot access it. I also have a file of substantial
> size which has the CR character as it's filename. 
> 

Try this:

	to edit "maps\033w" type "vi maps\\033w".  This interprets the
backslash as a literal charachter rather that the introducer to a special
charachter.  Similarly, for a file with a CR try "vi filename\<cr>"

Regards,
	Richard Meesters

samlb@pioneer.arc.nasa.gov (Sam Bassett RCD) (04/18/89)

	Nahhhh -- the '\033' is an Escape character, so using an extra
backslash will only get another odd file.
	What I would try is editing a junk file:

	'vi junk'

then doing a:

	:r maps^V<Esc>w

to read in the file (^V is the vi "literal escape"), and then  type:

	:1,$w! new.maps

and back out with 

	:q!

	Then get rid of the old file with:

	rm map*

and change rename the file you wrote:

	mv new.maps maps

Viola!


Sam'l Bassett, Sterling Software @ NASA Ames Research Center, 
Moffett Field CA 94035 Work: (415) 694-4792;  Home: (415) 454-7282
samlb%well@lll-crg.ARPA                 samlb@pioneer.arc.nasa.gov 
<Standard Disclaimer> := 'Sterling doesn't _have_ opinions -- much less NASA!'

guy@auspex.auspex.com (Guy Harris) (04/18/89)

>	to edit "maps\033w" type "vi maps\\033w".  This interprets the
>backslash as a literal charachter rather that the introducer to a special
>charachter.

"\033" doesn't mean "the character backslash, followed by the character
'0', followed by...", it means "the character with the octal value 33",
also known as "escape".  (He said "non-graphic character, and "\", "0",
and "3" are all graphic.)  To type in that character, you'd have to hit
the <ESC> key, or its moral equivalent, on your keyboard (or resort to
some trickery involving backquotes or something like that). 

>Similarly, for a file with a CR try "vi filename\<cr>"

Which, if you type it on your keyboard, will probably cause the terminal
driver to see your CR, map it to NL, and treat it as an end-of-line
terminator.  Your shell will probably treat the backslash at the end of
the line (it has only a NL following it, which means it's at the end of
the line) as a "continued on next line" indication (both the Bourne/Korn
and C shells do this), and wait for you to type another line. 

No, to manipulate a file with <CR> at the end of the name requires even
more trickery.  On *some* systems you can keep the terminal driver from
mapping the CR to an NL by typing your "literal-next" character,
normally ^V (control-V) before it.  Doing

	vi filename^V<return><return>

where ^V is control-V and <return> is the RETURN key, will let you edit
the file.  On other systems, you can't do this, and will have to use
other trickery.

In both cases, the best thing to do is probably to rename the file
first, giving it a name lacking non-graphic characters.  You can
generally do this with the "?" shell metacharacter:

	mv filename? filenameCR

"filename?" will match all files whose names consist of "filename"
followed by any character, including CR; the "?" matches any character.

If there is only one such file, for example filename<CR>, this will
rename that file "filenameCR" (make sure there's not already a file with
that name, otherwise "mv" will try to remove it; if there is such a
file, or if you don't like the name "filenameCR", pick another name). 

If there is more than one such file, this, unfortunately, won't work. 
Stronger medicine is needed.  One fix would be to make a new directory
in the current directory:

	mkdir temporary

move all the files in question into that directory:

	mv filename? temporary

move all the files *except* the one you wnat back out of that directory:

	mv temporary/filename1 .	# move into "." - current directory
	mv temporary/filename2 .
	...

and then deal with the funny-named file:

	mv temporary/filename? filenameCR

which moves it out of that directory and gives it a new name.

(Yes, this is a bit painful, and can be taken out of context and used to
bash UNIX.  I suspect the same could be done with just about any other
OS out there; there are situations where a given OS feature - in this
case, UNIX's willingness to put almost any byte value into a file name -
is a blessing, and situations where it's a nuisance.)

bobmon@iuvax.cs.indiana.edu (RAMontante) (04/19/89)

Won't  "vi maps*"  work?

ror@mplex.UUCP (Richard O'Rourke) (04/19/89)

In article <1460@auspex.auspex.com> guy@auspex.auspex.com (Guy Harris) writes:
>>	to edit "maps\033w" type "vi maps\\033w".  This interprets the
>>backslash as a literal charachter rather that the introducer to a special
>>charachter.
>
>"\033" doesn't mean "the character backslash, followed by the character

[ lots deleted ]

>"filename?" will match all files whose names consist of "filename"
>followed by any character, including CR; the "?" matches any character.

[ more deleted 
Some stuff about about creating a directory and moving the file with
funny name somewhere else to deal with it.... ]

>(Yes, this is a bit painful, and can be taken out of context and used to
>bash UNIX.  I suspect the same could be done with just about any other

Too muck work.
Why not:

vi filename[!\ -\~]

which is still not perfect, but probably eliminates any files with
names that are valid.  It even eliminates files that have a trailing
space.  If the file you are after has a trailing space do this:

vi filename[!\!-\~]     # Gets trailing non-printables

these work on my version of ksh anyway.  Assumes ASCII.

-------- Opinions expressed above are not necessarily anyone elses
                      |  Voice: 604 w 875-1461  | h 438-8249
Richard O' Rourke     |  Mail:  uunet!mplex!ror
-- 
-------- Opinions expressed above are not necessarily anyone elses
                      |  Voice: 604 w 875-1461  | h 438-8249
Richard O' Rourke     |  Mail:  uunet!mplex!ror

ram@tslanpar.UUCP (ram) (04/19/89)

In article <1460@auspex.auspex.com>, guy@auspex.auspex.com (Guy Harris) writes:
> >	to edit "maps\033w" type "vi maps\\033w".  This interprets the
> >backslash as a literal charachter rather that the introducer to a special
> >charachter.
> 
> "\033" doesn't mean "the character backslash, followed by the character
> '0', followed by...", it means "the character with the octal value 33",
> also known as "escape".  (He said "non-graphic character, and "\", "0",
> and "3" are all graphic.)  To type in that character, you'd have to hit
> the <ESC> key, or its moral equivalent, on your keyboard (or resort to
> some trickery involving backquotes or something like that). 

Of course, you are absolutely right.  In my haste I misread the question
and thus provided an answer to the wrong question.

Sorry,
Regards,
Richard Meesters.

simon@hhb.UUCP (simon chan) (04/21/89)

In article <4030@ucdavis.ucdavis.edu>, ccs013@castor.ucdavis.edu (Jason) writes:
> #!/csh/bin -f
> 
> foreach k (`ls`)
>     vi $k
> end

this command can do the same thing too, isn't it?
vi *

for an unusual name such as:
	a!@
you can do this:
	vi a??
regular expression always work for me!!!
							Simon Chan
							princeton!hhb!simon