change a character in filename to another

New to Debian (Or Linux in general)? Ask your questions here!

change a character in filename to another

Postby Agvaniot » 2017-08-15 16:35

im trying to take a dotted filiename "a.dotted.filename" and replace the "." with space
for example : "a dotted filename"
ive tried to come up with bunch of codes:
Code: Select all
dottedfilename=$1
${dottedfilename##*.*/' '/} | clipit

Code: Select all
sed -e  's/./ /g'` a.dotted.filename
Agvaniot
 
Posts: 42
Joined: 2017-07-26 13:07

Re: change a character in filename to another

Postby dasein » 2017-08-15 17:09

Homework
User avatar
dasein
 
Posts: 7775
Joined: 2011-03-04 01:06
Location: Terra Incantationum

Re: change a character in filename to another

Postby golinux » 2017-08-15 18:16

Agreed. Who would want spaces in a file name in real life?
May the FORK be with you!
User avatar
golinux
 
Posts: 1377
Joined: 2010-12-09 00:56
Location: not a 'buntard!

Re: change a character in filename to another

Postby Agvaniot » 2017-08-15 18:20

golinux wrote:Agreed. Who would want spaces in a file name in real life?

im trying to upload files to a sites and i need to state the full name of a file that is generaly
defaulted with . instead of spaces and send it to clipit for paste it in the site
Agvaniot
 
Posts: 42
Joined: 2017-07-26 13:07

Re: change a character in filename to another

Postby 4D696B65 » 2017-08-15 18:24

golinux wrote:Agreed. Who would want spaces in a file name in real life?

Windows users of course.
User avatar
4D696B65
 
Posts: 2196
Joined: 2009-06-28 06:09

Re: change a character in filename to another

Postby Agvaniot » 2017-08-15 18:26

sry i led you to belive that i want to change the dotted filename with spaces instead of dots
what i want to achieve is only to get the spaces version to clipit in order to paste it in the site im uploading the file
Agvaniot
 
Posts: 42
Joined: 2017-07-26 13:07

Re: change a character in filename to another

Postby GarryRicketson » 2017-08-15 18:35

A windows user would. On a linux system , using the cli it will not recognize a file name
with spaces, ...
The OP can change the file name to a file name with spaces, using a file manager,
just click the "rename", rename it with spaces.
How ever if they do that, and want to open the file from the command line
they won't be able to.

You can not have file names with spaces on a linux system, (or shouldn't have them)
You can change a filename using 'mv'
Code: Select all
man mv

Code: Select all
mv a.dotted.filename undotted
 


Example:
Won't work
Code: Select all
cat > name with spaces
cat: with: No such file or directory
cat: spaces: No such file or directory
$
 

Works:
Code: Select all
$ cat > name-like-this
 

Code: Select all
$ mv a.dotted.filename a dotted filename
usage: mv [-fi] source target
       mv [-fi] source ... directory
$ cp a.dotted.filename a dotted filename
usage: cp [-fip] [-R [-H | -L | -P]] source target
       cp [-fip] [-R [-H | -L | -P]] source ... directory
$ cat > a.dotted.filename               
this is it
 

=======
Code: Select all
$ mv a.dotted.filename  a dotted file name
usage: mv [-fi] source target
       mv [-fi] source ... directory
$ mv a.dotted.filename undotted
 
User avatar
GarryRicketson
 
Posts: 5042
Joined: 2015-01-20 22:16
Location: Durango, Mexico

Re: change a character in filename to another

Postby Agvaniot » 2017-08-15 19:23

your effort to explain this is very appreciated GarryRickeston.
in other words clipit cant handle a "spaced" filename.
Agvaniot
 
Posts: 42
Joined: 2017-07-26 13:07

Re: change a character in filename to another

Postby dasein » 2017-08-15 19:57

@Agvaniot:

The mere fact that GarryR can't figure out how do it doesn't mean it's impossible.

But as has been noted by several of us in this thread, this problem looks exactly like a homework problem--so much so that it's unlikely you'll convince anyone otherwise. But the good news is that homework problems are generally trivial to solve with the tiniest bit of research and thought,

What does your favorite search engine tell you about ways (yes, plural) to process spaces in a *nix filename?

@GarryR: for what I feel sure is the last time I will say it, if you can't give a good answer, would you please, for the love of whatever you hold Sacred, stop giving bad ones. Spreading ignorance and misinformation contributes less than nothing.
Last edited by dasein on 2017-08-15 20:13, edited 1 time in total.
User avatar
dasein
 
Posts: 7775
Joined: 2011-03-04 01:06
Location: Terra Incantationum

Re: change a character in filename to another

Postby pylkko » 2017-08-15 20:12

Garry, I just opened a terminal window on my desktop and created a file (using touch) named "name with spaces". Then edited content into it and the did the cat that you say is impossible. Well, it is not impossible.
User avatar
pylkko
 
Posts: 1325
Joined: 2014-11-06 19:02

Re: change a character in filename to another

Postby ruffwoof » 2017-08-15 21:56

If I open leafpad, enter some text and then save as test file.txt then I can cat that using cat "test file.txt" or using a wildcard such as cat "test fi"*

I have a number of files with spaces in the filename as sometimes I create quite a long filename that describes the content in perhaps 6 or 7 words. Guess I should have really used - or _ instead of spaces, but it does work with spaces.

Other characters are disallowed, for instance creating a filename of ;rm -rf / is blocked for obvious reasons.
ruffwoof
 
Posts: 261
Joined: 2016-08-20 21:00

Re: change a character in filename to another

Postby GarryRicketson » 2017-08-15 22:00

Hmm I just now, tried,
Code: Select all
touch name like this

And it created a file named "name", ???

@GarryR: for what I feel sure is the last time I will say it, if you can't give a good answer, would you please, for the love of whatever you hold Sacred, stop giving bad ones


And you call what you said a "good answer",... ?Before you derail a topic, with your attacks and flames, think about what you say, and apply it to yourself, if you can't give a good answer, then don't reply.
Look, I do not understand what your problems are, but my answer was a response to the OP, and I also did tell them :

by GarryRicketson » 2017-08-15 12:35 The OP can change the file name to a file name with spaces, using a file manager,
just click the "rename", rename it with spaces.


They should then also be able to submit it to "clip it" , with the new name.

Post by Agvaniot » 2017-08-15 13:23
your effort to explain this is very appreciated GarryRickeston.
in other words clipit cant handle a "spaced" filename.

Not exactly, what I mean is what I said, most unix and linux systems, do not see a file name or dir name, with spaces, for example, if you do rename a file, using your file manage, make a name with spaces, IE : " with spaces ", then try to view / or open
the file using the cli, Example :
Code: Select all
less with spaces

It will say "file not found".

pylkko wrote:Garry, I just opened a terminal window on my desktop and created a file (using touch) named "name with spaces". Then edited content into it and the did the cat that you say is impossible. Well, it is not impossible.

Interesting, as I showed above, it does not work for me,...
But in any event, agreed that does not mean it is 100% impossible, there may be some
way to configure the system so it does read file names that have spaces,...
If I did know a way to do this, I certainly would just share it with the OP and others,
instead of starting a flame war,... or just saying :
dasein wrote:Homework

@ dasein, If you can't or don't want to give a answer, then don't reply :mrgreen:
User avatar
GarryRicketson
 
Posts: 5042
Joined: 2015-01-20 22:16
Location: Durango, Mexico

Re: change a character in filename to another

Postby dasein » 2017-08-15 22:14

Speaking of people who have a long history of giving bad answers...
ruffwoof wrote:creating a filename of ;rm -rf / is blocked for obvious reasons.

Certainly not for the reason you seem to imply. The utterly innocuous ls -l / is "blocked" for exactly the same "reason"

I'll say it again, people who don't know what they are talking about should refrain from giving bad answers. It's profoundly unclear to me how such a notion could be perceived as in any way controversial. And it's mind-boggling to see anyone, much less a staff member, defend the practice.

This isn't funny. Really. No one comes here to be misinformed or misled. And folks who repeatedly give technically inaccurate answers out of ignorance are no better than (actually no different from) folks who would give bad answers just for lulz.

It's truly sad and pathetic that FDN's devotion to "free speech" supersedes their devotion to technical accuracy. It's an egregious and corrosive philosophy.

For instance, there is not a single accurate statement in this quote from GarryR
How ever if they do that, and want to open the file from the command line
they won't be able to.

You can not have file names with spaces on a linux system...


I will note once again that the initial problem looks like homework. There are exactly two characters that absolutely, positively cannot be used in a *nix filename. Determining which characters these are is left as an exercise for the curious.
User avatar
dasein
 
Posts: 7775
Joined: 2011-03-04 01:06
Location: Terra Incantationum

Re: change a character in filename to another

Postby sunrat » 2017-08-16 01:14

GarryRicketson wrote:Hmm I just now, tried,
Code: Select all
touch name like this

And it created a file named "name", ???
It would also create files "like " and "this". Try:
Code: Select all
touch "name like this"

GarryRicketson wrote:Not exactly, what I mean is what I said, most unix and linux systems, do not see a file name or dir name, with spaces, for example, if you do rename a file, using your file manage, make a name with spaces, IE : " with spaces ", then try to view / or open
the file using the cli, Example :
Code: Select all
less with spaces

Code: Select all
less "with spaces"


pylkko wrote:Garry, I just opened a terminal window on my desktop and created a file (using touch) named "name with spaces". Then edited content into it and the did the cat that you say is impossible. Well, it is not impossible.

Interesting, as I showed above, it does not work for me,...
But in any event, agreed that does not mean it is 100% impossible, there may be some
way to configure the system so it does read file names that have spaces,...

You can use quotes and escape:
Code: Select all
cat with\ spaces

Bash autocomplete helps with that.

If I did know a way to do this, I certainly would just share it with the OP and others,
instead of starting a flame war,... or just saying :
dasein wrote:Homework

@ dasein, If you can't or don't want to give a answer, then don't reply :mrgreen:

Please don't post that something can't be done when really it's just that you don't know how.
“ computer users can be divided into 2 categories:
Those who have lost data
...and those who have not lost data YET ”
Remember to BACKUP!
User avatar
sunrat
 
Posts: 2426
Joined: 2006-08-29 09:12
Location: Melbourne, Australia

Re: change a character in filename to another

Postby GarryRicketson » 2017-08-16 01:32

If you use
Code: Select all
 "
to enclose the file name:

Code: Select all
$ cat >this.file.txt
This is it
$
 

==========
Worked:
Code: Select all
$ mv this.file.txt "this file txt"
$ cat "this file txt"
This is it
$

 

So in other words , to change a.dotted.filename to a dotted filename:
Code: Select all
mv a.dotted.filename  "a dotted filename"

or use 'cp' instead if you want to keep the original file name.

I did not know this before, ... so there are ways to work with files that have spaces in
the names after all,...
=====EDited====
Posted at the same moment I was writing,...

by sunrat »
Please don't post that something can't be done when really it's just that you don't know how.

Well I really did not think it can be done, but when I saw what pylkko and ruffwoof said,
I did some searches, and find it can be done,.... I still think everything is easier just using
name without spaces,....
Any way, there also may be other ways to do this as well, Thanks sunrat,
you posted at the same time I was writing, and doing a search, any way, I had just now found this out, thanks for showing the OP how.
User avatar
GarryRicketson
 
Posts: 5042
Joined: 2015-01-20 22:16
Location: Durango, Mexico

Next

Return to Beginners Questions

Who is online

Users browsing this forum: No registered users and 9 guests

fashionable