I have requirement of parsing file names from given directory based on the pattern ( pattern will be parameter to script and can be any ).
for example, user enterred 2 params :
1) directory name : /dirname/
2) filename_pattern : *.dat_????
and there are 2 files in the directory as :
/dirname/a.dat_1234
/dirname/b.dat_4567
now I need to parse and retrive filename with static portion :
result :
1) a.dat_
2) b.dat_
Can you please give some pointers to solution, what are the ways this can be implemented.
Thanks in advance ...
Thanks
Abhijeet R
freakabhi:
I have requirement of parsing file names from given directory based on the pattern ( pattern will be parameter to script and can be any ).
for example, user enterred 2 params :
1) directory name : /dirname/
2) filename_pattern : *.dat_????
and there are 2 files in the directory as :
/dirname/a.dat_1234
/dirname/b.dat_4567
now I need to parse and retrive filename with static portion :
result :
1) a.dat_
2) b.dat_
Can you please give some pointers to solution, what are the ways this can be implemented.
Thanks in advance ...
Thanks
Abhijeet R
Hello Abhijeet,
Kindly use code tags for commands/codes in your posts. Following command may help you in same.
echo "/dirname/a.dat_1234" | awk '{sub(/.*\//,X,$0);sub(/\_.*/,"_",$0);print}'
Output will be as follows.
a.dat_
Thanks,
R. Singh
freakabhi:
I have requirement of parsing file names from given directory based on the pattern ( pattern will be parameter to script and can be any ).
for example, user enterred 2 params :
1) directory name : /dirname/
2) filename_pattern : *.dat_????
and there are 2 files in the directory as :
/dirname/a.dat_1234
/dirname/b.dat_4567
now I need to parse and retrive filename with static portion :
result :
1) a.dat_
2) b.dat_
Can you please give some pointers to solution, what are the ways this can be implemented.
Thanks in advance ...
Thanks
Abhijeet R
I don't understand what you're trying to do. The only static data matched by the pattern *.dat_????
is .dat_
. The 1st character of each filename is matched by the asterisk in the pattern and the 4 characters at the end of each filename is matched by the question marks.
1 Like
Moderator comments were removed during original forum migration.
1 Like