LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-09-2017, 12:56 PM   #1
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
BASH Script - ridding a weird char in filename


I got some kind of special char within the file name I cannot get rid of that is splitting the filename within the script so it loses it.
Code:
FILENAME=${FILENAME//[^A-Za-z0-9-"'" ]/ }
FILENAME=${FILENAME//[$'\t\r\n']}
FILENAME=$(echo -e "$FILENAME" | tr -d '\n')
FILENAME=$(echo -e "$FILENAME" | tr -d '\r')
FILENAME=$(echo -e "$FILENAME" | tr -d '\t')
FILENAME=$(echo -e "$FILENAME" | tr -d '\v')
FILENAME=$(echo -e "$FILENAME" | tr -d [:cntrl:])
FILENAME=$(echo -e "$FILENAME" | sed -e 's/[^A-Za-z0-9._-]/_/g' )

FILENAME=$(echo "$FILENAME" | fmt -u)
does not work.
Code:
echo "A: $FILENAME"
echo
userx%voider ⚡ production ⚡> ./moveFIles-3
A: /run/media/userx/3TB-External/X-TOCHECK-MUSIC/Art Of Noise/And What Have You Done With My Body, God? Cd4/Art Of Noise-Diversion 8 Diversion 2 Closest Close-up Close to The

echo "B: $path - $title - $ext"

B: /run/media/userx/3TB-External/X-TOCHECK-MUSIC/Art Of Noise/And What Have You Done With My Body, God? Cd4 - Art Of Noise-Diversion 8 Diversion 2 Closest Close-up Close to The - Art Of Noise-Diversion 8 Diversion 2 Closest Close-up Close to The

File not found: /run/media/userx/3TB-External/X-TOCHECK-MUSIC/Art Of Noise/And What Have You Done With My Body, God? Cd4/Art Of Noise-Diversion 8 Diversion 2 Closest Close-up Close to The
File not found: /run/media/userx/3TB-External/X-TOCHECK-MUSIC/Art Of Noise/And What Have You Done With My Body, God? Cd4/Art Of Noise-Diversion 8 Diversion 2 Closest Close-up Close to The
File not found: /run/media/userx/3TB-External/X-TOCHECK-MUSIC/Art Of Noise/And What Have You Done With My Body, God? Cd4/Art Of Noise-Diversion 8 Diversion 2 Closest Close-up Close to The
File not found: /run/media/userx/3TB-External/X-TOCHECK-MUSIC/Art Of Noise/And What Have You Done With My Body, God? Cd4/Art Of Noise-Diversion 8 Diversion 2 Closest Close-up Close to The
File not found: /run/media/userx/3TB-External/X-TOCHECK-MUSIC/Art Of Noise/And What Have You Done With My Body, God? Cd4/Art Of Noise-Diversion 8 Diversion 2 Closest Close-up Close to The

                        MAX    is 159
                        count  is 1
                                --------
                        left      158
The echo is within the script and that under it is the output.
Code:
echo "$FILENAME"

/run/media/userx/3TB-External/X-TOCHECK-MUSIC/Art Of Noise/Reduction/Art Of Noise-And I Placed My Fingers On Her Eyes As Though I Were
see image
Attached Thumbnails
Click image for larger version

Name:	Screenshot_crap-char-2017-06-09_12-49-09.png
Views:	37
Size:	45.2 KB
ID:	25222  

Last edited by BW-userx; 06-09-2017 at 01:07 PM.
 
Old 06-09-2017, 01:40 PM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
this mite help:
Code:
cat ./temp/ascii.c
#include "stdio.h"
 
main(int argc, char *argv[])
{
int c,n=0;
FILE * fstream;
 
fstream = fopen(argv[1], "r");
/*/ printf("fstream =  %d\n", fstream); /*/
c = fgetc(fstream);
 
while(c != EOF)
{
  if(c == 10 || c == 13)
   n++;
  if((c >= 0 && c <= 9) || (c >= 11 && c <= 12) || (c >= 14 && c <= 31))
   printf(" ");
  if(c >= 127)
   printf(" ");
  if(c >= 32 && c <= 126)
   printf("%c", c);
  c = fgetc(fstream);
}
fclose(fstream);
}
 
Old 06-09-2017, 02:02 PM   #3
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Original Poster
Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by schneidz View Post
this mite help:
Code:
cat ./temp/ascii.c
#include "stdio.h"
 
int main(int argc, char *argv[])
{
int c,n=0;
FILE * fstream;
 
fstream = fopen(argv[1], "r");
/*/ printf("fstream =  %d\n", fstream); /*/
c = fgetc(fstream);
 
while(c != EOF)
{
  if(c == 10 || c == 13)
   n++;
  if((c >= 0 && c <= 9) || (c >= 11 && c <= 12) || (c >= 14 && c <= 31))
   printf(" ");
  if(c >= 127)
   printf(" ");
  if(c >= 32 && c <= 126)
   printf("%c", c);
  c = fgetc(fstream);
}
fclose(fstream);

return 0;
}
needed

int main
return 0;

added but still don't know how to use it properly -- I ran it with one file off cli
Code:
userx%voider ⚡ Music ⚡> ./rid-files 'bowie david - the man who sold the world bonus tracks - 12 - moonage'$'\n''daydream ryko edition only.mp3'

 T    y   F    ,   Aa    >C C  %e { wb5,   zB   N        S  K   ]s     =sM=[R-"   R ! [     8  C    &   1 F  . P B  3k  ,)  ''F <% D  =i         LU}{     (  Eg  lP P   8* R     \K     i\ B    L   oI      Y     ~ r       u  /    ( S  r#FI  )w    B  1   NUq  i    $H    j k h |(J( o\  +   V
,     V   4   =7   ?9 X     cy   q  9    {  _ c     9  Y    F_          E    Z  p     H( D r*        e cR ,    zza  R INu  K      E S|  ) A  o9G2Uo  R$'{  5W '*nZ    BQE z     <(  W  hS    ,_y/         _ k lI       { o               >     @ R &      C      5  `  %   h   b 0   0  J$D  &A.  O  T    e     %f
 )   g/ N (z  ((   %      R  A         b      /E U C    k  xT  |   HC  =  Z 7  n    i ;O   I9EO k  " S n    SIA n  h  K   RR} z YuU     d  S  e         U  ?    v~   ^_    M   OJ ^  'k     o                ?         f  u _  x     01@!   *   -8D T   )   @  " $ S       yR N R   in 1  <         V 25 X`@  'e
Y   %{   %  4&'Q ,?Rb1~ I * 2 "   WUR6f  wE ,  # _I G @Y      g  j ;Or  e  '  9 5  ] U @ 3  Q    W    !            k  !Q R d    d|  $ ,K    ~ ?  g, a  ~ { E  T   t s   5 /T ct   w+ /  {     jSs  j        ~              ?         -I~{ f Uk   Iq>  ;t   F   qT  3   A  !  p8a L{p+   ]F/7Nm3     i >U E9{B jf G
 u [A       <      j wB j Hc      4    v      L }  l ,  E   GN ^       P = d  1 vf  o Qx 8 A      F       2(;    b%F<? ][ 4 ( I     N= & Y   $V M   V     e V* Eb   X  Y t  y };   m$  <   R t!ni$ P)  }h    8q  R         3  :   k    h ib{#a  0= a & :  R   %r  5Z  Yy)        [iy [  &  S \  X  Z XR VuJZ   m
 ,    ~ 6 ' j   "    .HF(* . I     < f=      o     q%EP- `  X  `  V   YQ  W     ,     0>   l   Ul|#RU    ~    m    m D g 3 Iv   7a    ]b'   &3,      1I1ULM  "n      j Z)jPAs   K =    #  j1  (m2    b#f     y2#D   8  Rjdg   E QQx|I YW  -     J Gy}Q>W9F*  )Q       , ,    =  R   3: t  p h C   R         G @ UK
 mp l ;          H  &O,    V t )  \ i       Y   I&  <M U@ ~ 7    X  .   ? i r  <V NY  u $*   z h   4<  ` 9   [:<      Pg      c 3     ZPuo7K fc!   kDU      A4     &      5&      V  " a 2Y   ND x           `Q     w+  ke `        {M#P i3T   $    $W  (            v)&    c    U  LB    f8   1    S   D TWH    Y
     m   H 8HI  h     t      V h  pQ   A  q MZB  s     RI (Je#  :< $     ) TQ   m    8o <  R   <        I ^ Z %   E$ 8     q  Pf   Bp   2=     b'     ,D   `  E ` T MI*  s w~|{   U~k" * |    W _( +: P +     k E25B + p$' L   R.nE\8t  $ [       Q   \   , f ]   Vn   (> = H  T Le E   C N!F  f\ q  T     _%#  m
    5 s  S  Q   wj g    /S{oXDTD    Z5B  D HN3: Z  .nE\$:q $ _( .p   r5S ` 8 , f  " )   (   E QU  X      Qh1   R;(7     f>V> q  {f|    W :    M    ,  *    I   a sj Y C { U4c   c           m   ]  ' N$nh   I       y  {  e N  G )   p    #  /Y           $[       w}B <   m;^   LG  3K                    H h Td
  kpYiq         Hs    3   (G N!_}   y     on  , t    6 '  a m    % >        B    ~   IZ1    v  GPd fp  j +I5 ;y   p : b  & p   E      D W   2    7<  P  bg   %  H  p  m/ Q  k* L \   l s      V         z  w   r0    nJ  s  Z  c" X X        GE    M Q V  ,   U    m  ~.  *   ]>     TK  rq   S x   }   |   iM # A
v Y    %    <    C<Ei 7   9       6      )=M  N    S    1  f I    w U  k $      R        BH ,  {   [        t}lm       X.= V F  *      :  J ( #  fR 2 S 4G   {B      "? CN Y#[     4 6 F  Zfa   s w]'           u     >  w      In     R .1 3  e G, s<  0    @  F     0 O j0     i  P   /\cmU      a$  s4 5S^
     \ Zm 8M L t!  r    +      z q  r       c 7M~ IW .  YR  )  Y z   Un=C    p&  } 0  S `   y   9  y  a>  8z    V  `  L i    e   w     5            \    V    =&N  }`G     ,H    +   3    % %   <9   ,m -     Tee    ,   Rn 4kEL ;Qq    !    x   ^X{   B      M;P  hA  ' x f k    i   t q   @1 L d         "t /~\
% M v     ?  :M9+K ez N    c 1M  z      ~3 zD          5 &      F G-    d/           T{     u*a rQ  R  , \,  ]    VS@       |LM    [C2-M    (   [    a   T   s I   8  C ) X~  ] p9 F9e  E*  .) J p L  t@    1   K z A   aO)G       ff    c   UG(    3  [  a  .   kg   f4 !      !M r l  *8 X    3V&      qC  <
     M      9    ,D8 h <0             ~   _# O c     |   i  t k   /5   G  Z D* @   ,L     $  X L /&    / JwT  z    {j9 Z mjx b      Yq  ]  m 1    h           0fX  Ar    =     ^L<   /    8R      [   OY  5 nV?   H OM $y   kJ  G 1       {6/   5      'F     @DK6R\  Ji,  j   -      w    b     v k ) K   3  <
J U+i < k    c   ?   X  =   bE ~   &   R  AR y N'J      7    V.: #/ o  ( "p  9 D4  R  b % !    @   V+   ^   | S 0^ {B  6    L         m  l m +  w|   D  }m I         iO?       !    E   xu = < & (  R.   "     &u %D  2JB   dp  $ Z$  C= x0    L 8  Qq  ]3 "] 8  r;w    [       Q ;x   []Q  #     I<     1"  XF  I
     Y H      {&   }fb z)  - j   0L  k      Mj                  `3   g \$g   )-< p      p  Q4 J\  nn         0n*%H   D  \D46    H |     'b f < ~ E M fb ^ F            WfW  3P   a j   \L0q        &  c  V   7Px1   Y E kh u L           9oeE 5 =     ^ f v)9 Q= m |7; \    u   ' =>t   (      Q  SL i          K#
U 0      .    DUm fl    .b   >      j]   ,.-G)  :7 $S)     H ( E/-$ <jD | @    , !r4 "ysL!     ,  r  0 !  R J U  .  9
that isn't even all of its output.

this is that little bugger that is messing it up
Code:
 moonage'$'\n''daydream

Last edited by BW-userx; 06-09-2017 at 02:05 PM.
 
Old 06-09-2017, 02:05 PM   #4
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
^ not really following what its input is but its supposed to scrub out all the non-printable ascii charterers.

fyi: its reading the content of the file not the filename (which i think is what you want changed) ?

Last edited by schneidz; 06-09-2017 at 02:07 PM.
 
Old 06-09-2017, 02:13 PM   #5
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,308
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
If you have the perl version of rename then you can remove whatever you want from the name:

Code:
rename -n -v 's/[^\w[:punct:]]//g' *sold*.mp3
 
Old 06-09-2017, 02:16 PM   #6
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Original Poster
Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
It is not even seeing it in the script
Code:
userx%voider ⚡ production ⚡> ./moveFIles-3
++ count=0
++ max=0
++ working_dir=/home/userx/Music/New
++ move_to=/run/media/userx/3TB-External/X-MUSIC
++ move_old_flac=/run/media/userx/3TB-External/OldFlac
++ script_dir=/home/userx/scripts/production
++ GirlSubString='Reference Of Female'
++ Gal1SubString='Guardians Of The Galaxy Deluxe'
++ Gal2SubString='Guardians Of The Galaxy Awesome Mix Vol. 2'
++ Gal3SubString='Guardians Of The Galaxy Vol. 1'
+++ find /home/userx/Music/New -type f '(' -iname '*.mp3' -o -name '*.MP3' -o -name '*.flac' ')'
+++ wc -l
++ max=2
++ read FILENAME
+++ find /home/userx/Music/New -type f '(' -iname '*.mp3' -o -name '*.MP3' -o -name '*.flac' ')'
++ FILENAME='/home/userx/Music/New/05 - You Probably Couldn'\''t See For The Lights But You Were Staring'
++ exit


userx%voider ⚡ production ⚡> ls ~/Music/New
'05 - You Probably Couldn'\''t See For The Lights But You Were Staring'$'\n''Straight At Me.mp3'
it gets chopped off right after the '$'\n' inside of the script.
 
Old 06-09-2017, 02:26 PM   #7
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Original Poster
Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by Turbocapitalist View Post
If you have the perl version of rename then you can remove whatever you want from the name:

Code:
rename -n -v 's/[^\w[:punct:]]//g' *sold*.mp3
yours minus the -n
Code:
userx%voider ⚡ New ⚡> rename  -v 's/[^\w[:punct:]]//g' '05 - You Probably Couldn'\''t See For The Lights But You Were Staring'$'\n''Straight At Me.mp3'
rename: not enough arguments

Usage:
 rename [options] <expression> <replacement> <file>...

Rename files.

Options:
 -v, --verbose    explain what is being done
 -s, --symlink    act on the target of symlinks
 -n, --no-act     do not make any changes

 -h, --help     display this help and exit
 -V, --version  output version information and exit

For more details see rename(1).
userx%voider ⚡ New ⚡>
modded it
Code:
userx%voider ⚡ New ⚡> rename -n -v 's/'$'\n'//g' '05 - You Probably Couldn'\''t See For The Lights But You Were Staring'$'\n''Straight At Me.mp3'
userx%voider ⚡ New ⚡> ls
'05 - You Probably Couldn'\''t See For The Lights But You Were Staring'$'\n''Straight At Me.mp3'
userx%voider ⚡ New ⚡> rename -v 's/'$'\n'//g' '05 - You Probably Couldn'\''t See For The Lights But You Were Staring'$'\n''Straight At Me.mp3'
userx%voider ⚡ New ⚡> ls
'05 - You Probably Couldn'\''t See For The Lights But You Were Staring'$'\n''Straight At Me.mp3'
userx%voider ⚡ New ⚡> rename -v 's/"\'"$""'\n'//g' '05 - You Probably Couldn'\''t See For The Lights But You Were Staring'$'\n''Straight At Me.mp3'
userx%voider ⚡ New ⚡> ls
'05 - You Probably Couldn'\''t See For The Lights But You Were Staring'$'\n''Straight At Me.mp3'
userx%voider ⚡ New ⚡>
still no go. maybe my formatting the search for is wrong - obliviously -

between the single quotes needs to go bye bye
Code:
Staring'$'\n''Straight
---> $'\n'

Last edited by BW-userx; 06-09-2017 at 02:29 PM.
 
Old 06-09-2017, 07:04 PM   #8
Laserbeak
Member
 
Registered: Jan 2017
Location: Manhattan, NYC NY
Distribution: Mac OS X, iOS, Solaris
Posts: 508

Rep: Reputation: 143Reputation: 143
You shouldn't have anything saved with a weird character, so maybe running it through a Perl script like:

Code:
#!/usr/bin/perl

use strict;
use warnings;

my $dir = "/path/to/my/files";

opendir (my $MYDIR, $dir) or die "Can't open directory $dir $!";
while (readdir ($MYDIR)) {
    my $oldfile = $_;
    s/^A-Za-z0-9//;
    system ("mv " . $dir . "/" . $oldfile . " " . $dir . "/" . $_);
}
 
Old 06-10-2017, 12:12 AM   #9
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
I am not really following what the issue is, but using your example file as input, the following works just fine:
Code:
$ ls tmp
'bowie david - the man who sold the world bonus tracks - 12 - moonage'$'\n''daydream ryko edition only.mp3'
$ cat bw.sh
#!/usr/bin/env bash

set -xv

for f in tmp/*
do
	echo "$f" | tr -d '\n'
done
$ ./bw.sh
for f in tmp/*
do
	echo "$f" | tr -d '\n'
done
+ for f in tmp/*
+ echo 'tmp/bowie david - the man who sold the world bonus tracks - 12 - moonage
daydream ryko edition only.mp3'
+ tr -d '\n'
tmp/bowie david - the man who sold the world bonus tracks - 12 - moonagedaydream ryko edition only.mp3
This also strips the new line from the echo so my prompt was at the end of the last string, but that was expected.

Please identify how this was not working for you?
 
Old 06-10-2017, 02:54 AM   #10
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,308
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
There is an imposter version in some distros.
Check to see which version of rename you have:

Code:
rename -V
You need the one based on CPAN's File::Rename to get any real results. If you don't have the right version, you can easily grab the right rename from CPAN.
 
Old 06-10-2017, 03:47 AM   #11
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
what I tried in that cases just use * instead of the strange chars, so:
mv "this is a file*name*wva a a" simple_name
mv simple_name whatever_you_want
 
Old 06-10-2017, 06:57 AM   #12
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Code:
touch "$(printf 'A\nB')"                             # create such a file

for i in A?B; do printf '%s' "$i" | od -tx1; done    # test it
0000000 41 0a 42

# rename
for i in A?B; do j=$(printf '%s' "$i" | tr '\n' '_'); mv -- "$i" "$j"; done

for i in A?B; do printf '%s' "$i" | od -tx1; done    # test again
0000000 41 5f 42

Last edited by NevemTeve; 06-10-2017 at 06:58 AM.
 
1 members found this post helpful.
Old 06-10-2017, 07:17 AM   #13
Teufel
Member
 
Registered: Apr 2012
Distribution: Gentoo
Posts: 616

Rep: Reputation: 142Reputation: 142
From my experience files with damaged filenames cannot be renamed. I can operate (delete) on such files only using wildcard.
rm -f *
I would try to convert these files using ffmpeg (to the same format with "-c copy" option) to new files, move them to separate folder and then remove old files with rm -f * command
 
Old 06-10-2017, 08:09 AM   #14
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Original Poster
Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by Laserbeak View Post
You shouldn't have anything saved with a weird character, so maybe running it through a Perl script like:

Code:
#!/usr/bin/perl

use strict;
use warnings;

my $dir = "/path/to/my/files";

opendir (my $MYDIR, $dir) or die "Can't open directory $dir $!";
while (readdir ($MYDIR)) {
    my $oldfile = $_;
    s/^A-Za-z0-9//;
    system ("mv " . $dir . "/" . $oldfile . " " . $dir . "/" . $_);
}
s/^A-Za-z0-9//; does not work. tried that it too is this
Code:
var=${var///^A-Za-z0-9//}
keeping Reg chars that dollar sign then new line is chops the file before it can get to it. so it looks like.

'left half name'$'\n''right half' reads

'left half name'$'\n'
'right half'
 
Old 06-10-2017, 08:10 AM   #15
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Original Poster
Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by Turbocapitalist View Post
There is an imposter version in some distros.
Check to see which version of rename you have:

Code:
rename -V
You need the one based on CPAN's File::Rename to get any real results. If you don't have the right version, you can easily grab the right rename from CPAN.
Code:
good morning userx
userx%voider ⚡ ~ ⚡> rename -V
rename from util-linux 2.30
userx%voider ⚡ ~ ⚡>
what version was I looking for??
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script to increment a filename jpv50 Programming 13 07-01-2015 06:25 PM
bash script - get filename created by script using variables aolong Linux - General 8 11-19-2009 12:40 PM
changing filename using Bash Script tmbigrigg Programming 10 11-10-2007 07:02 AM
Getting the first part of a filename in a BASH script trevelluk Programming 3 02-15-2005 01:06 AM
bash script - incrementing a filename in a script tslinux Programming 10 08-05-2003 11:58 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration