Finding the part of a filename


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding the part of a filename
# 15  
Old 08-22-2017
Quote:
Originally Posted by RudiC
That is difficult to understand or believe, respectively. I touched all those files:
Code:
ls -la lib*
-rw-rw-r-- 1 user user    0 Aug 21 22:26 libicudata.so
-rw-rw-r-- 1 user user    0 Aug 21 22:26 libicudata.so.54
-rw-rw-r-- 1 user user    0 Aug 21 22:26 libicui18n.so
-rw-rw-r-- 1 user user    0 Aug 21 22:26 libicui18n.so.54
-rw-rw-r-- 1 user user    0 Aug 21 22:26 libicuio.so
-rw-rw-r-- 1 user user    0 Aug 21 22:26 libicuio.so.54
-rw-rw-r-- 1 user user    0 Aug 21 22:26 libicuuc.so
-rw-rw-r-- 1 user user    0 Aug 21 22:26 libicuuc.so.54
-rw-rw-r-- 1 user user    0 Aug 21 22:26 libvclient_release_x64.so
-rw-rw-r-- 1 user user    0 Aug 21 20:36 libvclient_release_x64.so.734
-rw-rw-r-- 1 user user    0 Aug 21 22:26 libvclient_release_x64.so.740
-rw-rw-r-- 1 user user    0 Aug 21 22:26 libvkernel_release_x64.so
-rw-rw-r-- 1 user user    0 Aug 21 22:26 libvkernel_release_x64.so.740
-rw-rw-r-- 1 user user    0 Aug 21 22:26 libvreport_release_x64.so
-rw-rw-r-- 1 user user    0 Aug 21 22:26 libvreport_release_x64.so.740
-rw-rw-r-- 1 user user    0 Aug 21 22:26 libvshared_release_x64.so
-rw-rw-r-- 1 user user    0 Aug 21 22:26 libvshared_release_x64.so.740

and there will be just two files found for the pattern you gave:
Code:
echo libvclient_release_x64.so.*
libvclient_release_x64.so.734 libvclient_release_x64.so.740

There should NOT be that multitude of files listed that you present as the output of echo $number. What be the output of echo libvclient_release_x64.so.* in that environment?
Sorry, I can't follow you. Where did you run the
Code:
ls -la lib*

command?
# 16  
Old 08-22-2017
In a test directory on my host, where I created all the files you showed with the touch command.
Again: the error you posted is not reproducible without further information. The reason I insist is that the proposal in post#2 is the most cost / resource effective one and should work perfectly.
# 17  
Old 08-22-2017
Quote:
Originally Posted by RudiC
In a test directory on my host, where I created all the files you showed with the touch command.
Again: the error you posted is not reproducible without further information. The reason I insist is that the proposal in post#2 is the most cost / resource effective one and should work perfectly.
Hello RudiC,

you can download the Valentina Server Linux 64 DEB deb package from here: Download
then unpack it with
Code:
ar x vserver_x64_7_lin.deb

Then you get three files:
control.tar.gz
data.tar.xz
debian-binary

Further, you can unpack the data.tar.xz archive and get three directories:
etc/
opt/
usr/

In the opt/VServer/ dir there is among others the
vcomponents/ dir, which contains the files which are in question.

You can see there that in vcomponents/ dir is only one version of libraries, currently it is 740 version. So at a time there is only one number at the end of some filenames.

When my ebuild on Gentoo Linux system unpack the downloaded deb package, it gets the exact dirs and files out there. Naturally, the files and it's versions will change at time.

I hope I explained to you what is the situation. Right?

Best, Pál
# 18  
Old 08-22-2017
If it is made very sure that there will be only one numbered file version at a time, then why do you need to find out the sequence number? Create the symlink immediately to the only version that exists.
I presume the dosym command does exactly this: create a symbolic link. If not so, what does it do?
This User Gave Thanks to RudiC For This Post:
# 19  
Old 08-22-2017
I think i can clear up the confusion:

What rdtx1 gave you is a so-called variable expansion in the shell.

This:
Quote:
Originally Posted by rdrtx1
Code:
specific_filename=libvclient_release_x64.so.740

number=${specific_filename##*[.]}

Respectively the last part: ${variable_name##*[.]} means: take from the content of variable_name everything after the last ".". To understand how it works try this:

Code:
# string="bla.foo.before-dot.after-dot"
# echo ${string##*[.]}
after-dot

So, rdtx1 showed you a way of isolating the part you are interested in from the full filename. You will still have to provide the full filename first.

But you tried to use an asterisk "*" as part of the filename. This is expanded by the shell not to a single filename but a list of names. Consider the following:

Code:
# ls -l
total 0
-rw-rw-r-- 1 bakunin users 0 Aug 22 15:04 afile.123
-rw-rw-r-- 1 bakunin users 0 Aug 22 15:04 bfile.456
-rw-rw-r-- 1 bakunin users 0 Aug 22 15:04 cfile.789

# var=afile.123          # storing a fixed name in the variable
# echo ${var##*[.]}
123

# var=*                    # storing the asterisk
# echo $var
afile.123 bfile.456 cfile.789

# echo ${var##*[.]}

The reason for this is that in fact the content of the variable is "*" and you can't remove any "part before the dot" because there isn't any dot. But when you try to display this asterisk with the echo-command the shell replaces it with a list of files named along the pattern (i.e. when you specifiy "abc*" the pattern is "all files with names starting with "abc").

Therefor you need to not use the asterisk as part of your variables content but the list it produces - and then trim the resulting filenames one at a time with the expression rdtx1 gave you. Like this:

Code:
ls | while read filename ; do
     echo "filename is: $filename trimmed filename is: ${filename##*[.]}"
done

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add part of directory name to filename

Hello, I need to add a part of folder name to the files inside it. For instance the file is HMCBackup_20150430.155027.tgz and it is under directory /nim/dr/HMCBackup/cops22 I need to add cops22 to the file name so as it would be cops22_HMCBackup_20150430.155027.tgz Any help in doing... (10 Replies)
Discussion started by: hasn318
10 Replies

2. UNIX for Dummies Questions & Answers

Replacing part of filename

Hi guys! I have quite a lot of files like all_10001_ct1212307460308.alf* and I want to get rid of the first number for all at once like: all_ct1212307460308.alf* How can I do this in the shell? (12 Replies)
Discussion started by: TimmyTiz
12 Replies

3. Shell Programming and Scripting

Extract a part of a filename containing a particular word

Hi All, Thanks in Advance Shell Script or Perl Script I am working on a shell script. I need some assistance. My Requirement: 1) There are some set of files in a directory like given below OTP_UFSC_20120530000000_acc.csv OTP_UFSC_20120530000000_faf.csv... (7 Replies)
Discussion started by: aealexanderraj
7 Replies

4. Programming

to extract all the part of the filename before a particular word in the filename

Hi All, Thanks in Advance I am working on a shell script. I need some assistance. My code: if then set "subscriber" "promplan" "mapping" "dedicatedaccount" "faflistSub" "faflistAcc" "accumulator"\ "pam_account"; for i in 1 2 3 4 5 6 7 8;... (0 Replies)
Discussion started by: aealexanderraj
0 Replies

5. UNIX for Dummies Questions & Answers

to extract all the part of the filename before a particular word in the filename

Hi All, Thanks in Advance I am working on a shell script. I need some assistance. My Requirement: 1) There are some set of files in a directory like given below OTP_UFSC_20120530000000_acc.csv OTP_UFSC_20120530000000_faf.csv OTP_UFSC_20120530000000_prom.csv... (0 Replies)
Discussion started by: aealexanderraj
0 Replies

6. Shell Programming and Scripting

cut the some part in filename

Hi All, I have the file & name is "/a/b/c/d/e/xyz.dat" I need "/a/b/c/d/e/" from the above file name. I tryning with echo and awk. But it not come. Please help me in this regard. Thanks & Regards, Dathu (3 Replies)
Discussion started by: pdathu
3 Replies

7. Shell Programming and Scripting

Getting part of a filename

Hi All, I'm trying to get part of a filename and my skill with regular expression are lacking. I know I need to use SED but have no idea how to use it. I'm hoping that someone can help me out. The file names would be: prefix<partwewant>suffix.extension the prefix and suffix are always 3... (4 Replies)
Discussion started by: imonkey
4 Replies

8. UNIX for Dummies Questions & Answers

Strip part from filename

I've many file like this 01-file 01_-_file 01_-_file 01_-_file 01_-_file 01-file I would remove bold part from filename. Suggestions?Thanks (4 Replies)
Discussion started by: cv313x
4 Replies

9. Shell Programming and Scripting

detecting the part of a filename

I like to have the date in the 2008-09-01 format at the beginning of my filenames. I then hyphenate after that and then have my filename. I have a script that creates this for me. However, I may be working on files that already have the date format already in there and so I don't want to have a... (4 Replies)
Discussion started by: mainegate
4 Replies

10. Shell Programming and Scripting

part of a filename

Hi, I need to extract only a part of the filenames of some files. The files are named this way : .tap_profile_SIT02 I want the "SIT02" part, which is not the same for each file. I was able to get what I want with bash, but not with ksh. Here is the command I used in bash : find... (8 Replies)
Discussion started by: flame_eagle
8 Replies
Login or Register to Ask a Question