AWK - change the file name (special characters)
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I have two files:
~/Pulpit/kot$ find . -name "*jpg" -printf "%fn"
1.jpg
`[~!($%^_&*).___"`]`1.jpg
I want to change their name to:
_home_pic_Pulpit_kot_1.jpg
_home_pic_Pulpit_kot_`[~!($%^_&*).___"`]`1.jpg
I use this command:
~/Pulpit/kot$ find $PWD -name "*.jpg" | mawk 'c=$0; gsub("/", "_", c)system("echo mv -v " $0 " " c)'
mv -v /home/pic/Pulpit/kot/1.jpg _home_pic_Pulpit_kot_1.jpg
/bin/sh: Syntax error: word unexpected (expecting ")")
EDIT:
This command works.
find $PWD -name "*.jpg" -exec bash -c 'mv "$0" "$0////_"' ;
How to do the same with mawk?
EDIT- 1:
This solution works:
find $PWD -name "*.jpg" | mawk 'a=$0gsub("/", "_")system("mv -v '"'"'" a "'"'"' '"'"'" $0 "'"'"'")'
find $PWD -name "*.jpg" | mawk 'a=$0gsub("/", "_")system("mv -v '''" a "''' '''" $0 "''' ")'
find $PWD -name "*.jpg" | mawk 'a=$0gsub("/", "_")system("mv -v 47" a "47 47" $0 "47 ")'
awk
 |Â
show 7 more comments
up vote
1
down vote
favorite
I have two files:
~/Pulpit/kot$ find . -name "*jpg" -printf "%fn"
1.jpg
`[~!($%^_&*).___"`]`1.jpg
I want to change their name to:
_home_pic_Pulpit_kot_1.jpg
_home_pic_Pulpit_kot_`[~!($%^_&*).___"`]`1.jpg
I use this command:
~/Pulpit/kot$ find $PWD -name "*.jpg" | mawk 'c=$0; gsub("/", "_", c)system("echo mv -v " $0 " " c)'
mv -v /home/pic/Pulpit/kot/1.jpg _home_pic_Pulpit_kot_1.jpg
/bin/sh: Syntax error: word unexpected (expecting ")")
EDIT:
This command works.
find $PWD -name "*.jpg" -exec bash -c 'mv "$0" "$0////_"' ;
How to do the same with mawk?
EDIT- 1:
This solution works:
find $PWD -name "*.jpg" | mawk 'a=$0gsub("/", "_")system("mv -v '"'"'" a "'"'"' '"'"'" $0 "'"'"'")'
find $PWD -name "*.jpg" | mawk 'a=$0gsub("/", "_")system("mv -v '''" a "''' '''" $0 "''' ")'
find $PWD -name "*.jpg" | mawk 'a=$0gsub("/", "_")system("mv -v 47" a "47 47" $0 "47 ")'
awk
2
Do you really have a file named./`[~!($%^_&*).___"`]`1.jpg
? I am utterly horrified. I generally stick to the POSIX Portable Filename Character Set. What are you trying to do?
â jw013
May 3 '12 at 11:01
Yes. I have a test file: See my edit.
â nowy
May 3 '12 at 11:06
I want to change "/" to "_" (as in gawk).
â nowy
May 3 '12 at 11:14
1
Are you sure/
is in file name? Like in your output seems./
is just added by find. Tryfind . -name "*jpg" -printf "%fn"
instead to output it without./
in the begin.
â rush
May 3 '12 at 11:40
1
@nowy I'm a bit confused by what you are doing./
is never a valid character in a file name because it is the path separator. Replacing/
in a path means moving the files to a completely directory, not just a simple file name transformation. Whereas./file
is rather ordinary,._file
is a dotfile / hidden file, whereasdir/file
becomesdir_file
. Is that really what you intend?
â jw013
May 3 '12 at 12:05
 |Â
show 7 more comments
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have two files:
~/Pulpit/kot$ find . -name "*jpg" -printf "%fn"
1.jpg
`[~!($%^_&*).___"`]`1.jpg
I want to change their name to:
_home_pic_Pulpit_kot_1.jpg
_home_pic_Pulpit_kot_`[~!($%^_&*).___"`]`1.jpg
I use this command:
~/Pulpit/kot$ find $PWD -name "*.jpg" | mawk 'c=$0; gsub("/", "_", c)system("echo mv -v " $0 " " c)'
mv -v /home/pic/Pulpit/kot/1.jpg _home_pic_Pulpit_kot_1.jpg
/bin/sh: Syntax error: word unexpected (expecting ")")
EDIT:
This command works.
find $PWD -name "*.jpg" -exec bash -c 'mv "$0" "$0////_"' ;
How to do the same with mawk?
EDIT- 1:
This solution works:
find $PWD -name "*.jpg" | mawk 'a=$0gsub("/", "_")system("mv -v '"'"'" a "'"'"' '"'"'" $0 "'"'"'")'
find $PWD -name "*.jpg" | mawk 'a=$0gsub("/", "_")system("mv -v '''" a "''' '''" $0 "''' ")'
find $PWD -name "*.jpg" | mawk 'a=$0gsub("/", "_")system("mv -v 47" a "47 47" $0 "47 ")'
awk
I have two files:
~/Pulpit/kot$ find . -name "*jpg" -printf "%fn"
1.jpg
`[~!($%^_&*).___"`]`1.jpg
I want to change their name to:
_home_pic_Pulpit_kot_1.jpg
_home_pic_Pulpit_kot_`[~!($%^_&*).___"`]`1.jpg
I use this command:
~/Pulpit/kot$ find $PWD -name "*.jpg" | mawk 'c=$0; gsub("/", "_", c)system("echo mv -v " $0 " " c)'
mv -v /home/pic/Pulpit/kot/1.jpg _home_pic_Pulpit_kot_1.jpg
/bin/sh: Syntax error: word unexpected (expecting ")")
EDIT:
This command works.
find $PWD -name "*.jpg" -exec bash -c 'mv "$0" "$0////_"' ;
How to do the same with mawk?
EDIT- 1:
This solution works:
find $PWD -name "*.jpg" | mawk 'a=$0gsub("/", "_")system("mv -v '"'"'" a "'"'"' '"'"'" $0 "'"'"'")'
find $PWD -name "*.jpg" | mawk 'a=$0gsub("/", "_")system("mv -v '''" a "''' '''" $0 "''' ")'
find $PWD -name "*.jpg" | mawk 'a=$0gsub("/", "_")system("mv -v 47" a "47 47" $0 "47 ")'
awk
awk
edited 35 mins ago
MUmla
112
112
asked May 3 '12 at 10:42
nowy
84
84
2
Do you really have a file named./`[~!($%^_&*).___"`]`1.jpg
? I am utterly horrified. I generally stick to the POSIX Portable Filename Character Set. What are you trying to do?
â jw013
May 3 '12 at 11:01
Yes. I have a test file: See my edit.
â nowy
May 3 '12 at 11:06
I want to change "/" to "_" (as in gawk).
â nowy
May 3 '12 at 11:14
1
Are you sure/
is in file name? Like in your output seems./
is just added by find. Tryfind . -name "*jpg" -printf "%fn"
instead to output it without./
in the begin.
â rush
May 3 '12 at 11:40
1
@nowy I'm a bit confused by what you are doing./
is never a valid character in a file name because it is the path separator. Replacing/
in a path means moving the files to a completely directory, not just a simple file name transformation. Whereas./file
is rather ordinary,._file
is a dotfile / hidden file, whereasdir/file
becomesdir_file
. Is that really what you intend?
â jw013
May 3 '12 at 12:05
 |Â
show 7 more comments
2
Do you really have a file named./`[~!($%^_&*).___"`]`1.jpg
? I am utterly horrified. I generally stick to the POSIX Portable Filename Character Set. What are you trying to do?
â jw013
May 3 '12 at 11:01
Yes. I have a test file: See my edit.
â nowy
May 3 '12 at 11:06
I want to change "/" to "_" (as in gawk).
â nowy
May 3 '12 at 11:14
1
Are you sure/
is in file name? Like in your output seems./
is just added by find. Tryfind . -name "*jpg" -printf "%fn"
instead to output it without./
in the begin.
â rush
May 3 '12 at 11:40
1
@nowy I'm a bit confused by what you are doing./
is never a valid character in a file name because it is the path separator. Replacing/
in a path means moving the files to a completely directory, not just a simple file name transformation. Whereas./file
is rather ordinary,._file
is a dotfile / hidden file, whereasdir/file
becomesdir_file
. Is that really what you intend?
â jw013
May 3 '12 at 12:05
2
2
Do you really have a file named
./`[~!($%^_&*).___"`]`1.jpg
? I am utterly horrified. I generally stick to the POSIX Portable Filename Character Set. What are you trying to do?â jw013
May 3 '12 at 11:01
Do you really have a file named
./`[~!($%^_&*).___"`]`1.jpg
? I am utterly horrified. I generally stick to the POSIX Portable Filename Character Set. What are you trying to do?â jw013
May 3 '12 at 11:01
Yes. I have a test file: See my edit.
â nowy
May 3 '12 at 11:06
Yes. I have a test file: See my edit.
â nowy
May 3 '12 at 11:06
I want to change "/" to "_" (as in gawk).
â nowy
May 3 '12 at 11:14
I want to change "/" to "_" (as in gawk).
â nowy
May 3 '12 at 11:14
1
1
Are you sure
/
is in file name? Like in your output seems ./
is just added by find. Try find . -name "*jpg" -printf "%fn"
instead to output it without ./
in the begin.â rush
May 3 '12 at 11:40
Are you sure
/
is in file name? Like in your output seems ./
is just added by find. Try find . -name "*jpg" -printf "%fn"
instead to output it without ./
in the begin.â rush
May 3 '12 at 11:40
1
1
@nowy I'm a bit confused by what you are doing.
/
is never a valid character in a file name because it is the path separator. Replacing /
in a path means moving the files to a completely directory, not just a simple file name transformation. Whereas ./file
is rather ordinary, ._file
is a dotfile / hidden file, whereas dir/file
becomes dir_file
. Is that really what you intend?â jw013
May 3 '12 at 12:05
@nowy I'm a bit confused by what you are doing.
/
is never a valid character in a file name because it is the path separator. Replacing /
in a path means moving the files to a completely directory, not just a simple file name transformation. Whereas ./file
is rather ordinary, ._file
is a dotfile / hidden file, whereas dir/file
becomes dir_file
. Is that really what you intend?â jw013
May 3 '12 at 12:05
 |Â
show 7 more comments
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
You probably just need to put single quotes around the filename arguments to mv
. It's ugly but...
change
system("echo mv -v " $0 " " c)
to
system("echo mv -v '"'"'" $0 "'"'"' '"'"'" c "'"'"'")
Your solution works. Thank you very much.find $PWD -name "*.jpg" | mawk 'a=$0gsub("/", "_")system("mv -v '"'"'" a "'"'"' '"'"'" $0 "'"'"'")'
â nowy
May 3 '12 at 14:47
1
@nowy If I understand what you're trying to do correctly, this isn't correct. Try with a'
in the file name. Also, that'"'"'"
is horribly unreadable. I recommend'''"
or47"
.
â Gilles
May 3 '12 at 23:41
@Gilles Thank you for your help. This is a good way:find $PWD -name "*.jpg" | mawk 'a=$0gsub("/", "_")system("mv -v '''" a "''' '''" $0 "''' ")'
or:find $PWD -name "*.jpg" | mawk 'a=$0gsub("/", "_")system("mv -v 47" a "47 47" $0 "47 ")'
â nowy
May 4 '12 at 7:39
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
You probably just need to put single quotes around the filename arguments to mv
. It's ugly but...
change
system("echo mv -v " $0 " " c)
to
system("echo mv -v '"'"'" $0 "'"'"' '"'"'" c "'"'"'")
Your solution works. Thank you very much.find $PWD -name "*.jpg" | mawk 'a=$0gsub("/", "_")system("mv -v '"'"'" a "'"'"' '"'"'" $0 "'"'"'")'
â nowy
May 3 '12 at 14:47
1
@nowy If I understand what you're trying to do correctly, this isn't correct. Try with a'
in the file name. Also, that'"'"'"
is horribly unreadable. I recommend'''"
or47"
.
â Gilles
May 3 '12 at 23:41
@Gilles Thank you for your help. This is a good way:find $PWD -name "*.jpg" | mawk 'a=$0gsub("/", "_")system("mv -v '''" a "''' '''" $0 "''' ")'
or:find $PWD -name "*.jpg" | mawk 'a=$0gsub("/", "_")system("mv -v 47" a "47 47" $0 "47 ")'
â nowy
May 4 '12 at 7:39
add a comment |Â
up vote
0
down vote
accepted
You probably just need to put single quotes around the filename arguments to mv
. It's ugly but...
change
system("echo mv -v " $0 " " c)
to
system("echo mv -v '"'"'" $0 "'"'"' '"'"'" c "'"'"'")
Your solution works. Thank you very much.find $PWD -name "*.jpg" | mawk 'a=$0gsub("/", "_")system("mv -v '"'"'" a "'"'"' '"'"'" $0 "'"'"'")'
â nowy
May 3 '12 at 14:47
1
@nowy If I understand what you're trying to do correctly, this isn't correct. Try with a'
in the file name. Also, that'"'"'"
is horribly unreadable. I recommend'''"
or47"
.
â Gilles
May 3 '12 at 23:41
@Gilles Thank you for your help. This is a good way:find $PWD -name "*.jpg" | mawk 'a=$0gsub("/", "_")system("mv -v '''" a "''' '''" $0 "''' ")'
or:find $PWD -name "*.jpg" | mawk 'a=$0gsub("/", "_")system("mv -v 47" a "47 47" $0 "47 ")'
â nowy
May 4 '12 at 7:39
add a comment |Â
up vote
0
down vote
accepted
up vote
0
down vote
accepted
You probably just need to put single quotes around the filename arguments to mv
. It's ugly but...
change
system("echo mv -v " $0 " " c)
to
system("echo mv -v '"'"'" $0 "'"'"' '"'"'" c "'"'"'")
You probably just need to put single quotes around the filename arguments to mv
. It's ugly but...
change
system("echo mv -v " $0 " " c)
to
system("echo mv -v '"'"'" $0 "'"'"' '"'"'" c "'"'"'")
answered May 3 '12 at 14:16
glenn jackman
49.1k469106
49.1k469106
Your solution works. Thank you very much.find $PWD -name "*.jpg" | mawk 'a=$0gsub("/", "_")system("mv -v '"'"'" a "'"'"' '"'"'" $0 "'"'"'")'
â nowy
May 3 '12 at 14:47
1
@nowy If I understand what you're trying to do correctly, this isn't correct. Try with a'
in the file name. Also, that'"'"'"
is horribly unreadable. I recommend'''"
or47"
.
â Gilles
May 3 '12 at 23:41
@Gilles Thank you for your help. This is a good way:find $PWD -name "*.jpg" | mawk 'a=$0gsub("/", "_")system("mv -v '''" a "''' '''" $0 "''' ")'
or:find $PWD -name "*.jpg" | mawk 'a=$0gsub("/", "_")system("mv -v 47" a "47 47" $0 "47 ")'
â nowy
May 4 '12 at 7:39
add a comment |Â
Your solution works. Thank you very much.find $PWD -name "*.jpg" | mawk 'a=$0gsub("/", "_")system("mv -v '"'"'" a "'"'"' '"'"'" $0 "'"'"'")'
â nowy
May 3 '12 at 14:47
1
@nowy If I understand what you're trying to do correctly, this isn't correct. Try with a'
in the file name. Also, that'"'"'"
is horribly unreadable. I recommend'''"
or47"
.
â Gilles
May 3 '12 at 23:41
@Gilles Thank you for your help. This is a good way:find $PWD -name "*.jpg" | mawk 'a=$0gsub("/", "_")system("mv -v '''" a "''' '''" $0 "''' ")'
or:find $PWD -name "*.jpg" | mawk 'a=$0gsub("/", "_")system("mv -v 47" a "47 47" $0 "47 ")'
â nowy
May 4 '12 at 7:39
Your solution works. Thank you very much.
find $PWD -name "*.jpg" | mawk 'a=$0gsub("/", "_")system("mv -v '"'"'" a "'"'"' '"'"'" $0 "'"'"'")'
â nowy
May 3 '12 at 14:47
Your solution works. Thank you very much.
find $PWD -name "*.jpg" | mawk 'a=$0gsub("/", "_")system("mv -v '"'"'" a "'"'"' '"'"'" $0 "'"'"'")'
â nowy
May 3 '12 at 14:47
1
1
@nowy If I understand what you're trying to do correctly, this isn't correct. Try with a
'
in the file name. Also, that '"'"'"
is horribly unreadable. I recommend '''"
or 47"
.â Gilles
May 3 '12 at 23:41
@nowy If I understand what you're trying to do correctly, this isn't correct. Try with a
'
in the file name. Also, that '"'"'"
is horribly unreadable. I recommend '''"
or 47"
.â Gilles
May 3 '12 at 23:41
@Gilles Thank you for your help. This is a good way:
find $PWD -name "*.jpg" | mawk 'a=$0gsub("/", "_")system("mv -v '''" a "''' '''" $0 "''' ")'
or: find $PWD -name "*.jpg" | mawk 'a=$0gsub("/", "_")system("mv -v 47" a "47 47" $0 "47 ")'
â nowy
May 4 '12 at 7:39
@Gilles Thank you for your help. This is a good way:
find $PWD -name "*.jpg" | mawk 'a=$0gsub("/", "_")system("mv -v '''" a "''' '''" $0 "''' ")'
or: find $PWD -name "*.jpg" | mawk 'a=$0gsub("/", "_")system("mv -v 47" a "47 47" $0 "47 ")'
â nowy
May 4 '12 at 7:39
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f37816%2fawk-change-the-file-name-special-characters%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
2
Do you really have a file named
./`[~!($%^_&*).___"`]`1.jpg
? I am utterly horrified. I generally stick to the POSIX Portable Filename Character Set. What are you trying to do?â jw013
May 3 '12 at 11:01
Yes. I have a test file: See my edit.
â nowy
May 3 '12 at 11:06
I want to change "/" to "_" (as in gawk).
â nowy
May 3 '12 at 11:14
1
Are you sure
/
is in file name? Like in your output seems./
is just added by find. Tryfind . -name "*jpg" -printf "%fn"
instead to output it without./
in the begin.â rush
May 3 '12 at 11:40
1
@nowy I'm a bit confused by what you are doing.
/
is never a valid character in a file name because it is the path separator. Replacing/
in a path means moving the files to a completely directory, not just a simple file name transformation. Whereas./file
is rather ordinary,._file
is a dotfile / hidden file, whereasdir/file
becomesdir_file
. Is that really what you intend?â jw013
May 3 '12 at 12:05