Finding the part of a filename


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding the part of a filename
# 8  
Old 08-21-2017
Quote:
Originally Posted by csanyipal
I am trying to use this in my ebuild:
Code:
lvcltno=awk 'FNR==1{if(name){close(name)};split(FILENAME, a,".");print a[3];name=FILENAME;nextfile}' \
           opt/VServer/vcomponents/libvclient_release_x64.so.*
dosym libvclient_release_x64.so."${lvcltno}" "${EPREFIX}/usr/$(get_libdir)/libvclient_release_x64.so"

but it does not work, the symlink is not created properly:
Code:
libvclient_release_x64.so -> libvclient_release_x64.so.

It seems that that the link is pointing to it self. Why? How can I fix this?
Hello csanyipal,

Not sure what you are trying to do, so please try my suggestion into a test environment only.
Also in awk we can't use variable values by using $, by seeing your command I tried making following command(considering your command works on shell only).
Code:
awk -vLVCLINTO=${lvcltno} -veprefix=${EPREFIX} -vGET_LIBDIR=$(get_libdir) 'FNR==1{if(name){close(name)};split(FILENAME, a,".");;name=FILENAME;system("dosym libvclient_release_x64.so."LVCLINTO FS eprefix"/usr/"GET_LIBDIR"/libvclient_release_x64.so");nextfile}' /opt/VServer/vcomponents/libvclient_release_x64.so.*

Thanks,
R. Singh

Last edited by RavinderSingh13; 08-21-2017 at 02:37 PM..
# 9  
Old 08-21-2017
Hello R.,
Quote:
Originally Posted by RavinderSingh13
Hello csanyipal,
Not sure what you are trying to do, so please try my suggestion into a test environment only.
R. Singh
I am trying to add the output of your awk command to a variable, and later in my ebuild to use this variable. I search and find how to do it:
Code:
lvcltno="$(awk 'FNR==1{if(name){close(name)};split(FILENAME, a,".");print a[3];name=FILENAME;nextfile}' opt/VServer/vcomponents/libvclient_release_x64.so.*)"
dosym libvclient_release_x64.so."${lvcltno}" "${EPREFIX}/usr/$(get_libdir)/libvclient_release_x64.so"

Now my ebuild creates symlinks properly.
Best, Pál
# 10  
Old 08-21-2017
There is some essential info missing in your specification:
- Is it always the same (root or base, without sequence No.) file name? If not, how is the (partial) file name supplied?
- Is there always one single version only or can there be multiple ? If so, which version do you want?
- Why does specific_filename=libvclient_release_x64.so.* "not do the job"?What's the error?
# 11  
Old 08-21-2017
Quote:
Originally Posted by RudiC
There is some essential info missing in your specification:
- Is it always the same (root or base, without sequence No.) file name? If not, how is the (partial) file name supplied?
- Is there always one single version only or can there be multiple ? If so, which version do you want?
- Why does specific_filename=libvclient_release_x64.so.* "not do the job"?What's the error?
It is always the same file name, without the trailing number which changes only.
I do not understand your second question. Version of what?
# 12  
Old 08-21-2017
Do e.g.
Code:
libvclient_release_x64.so.734
libvclient_release_x64.so.740

exist at the same time?
# 13  
Old 08-21-2017
Quote:
Originally Posted by RudiC
Do e.g.
Code:
libvclient_release_x64.so.734
libvclient_release_x64.so.740

exist at the same time?
No, it does not. There will be only one version of that file out there.

---------- Post updated at 10:13 PM ---------- Previous update was at 10:05 PM ----------

Quote:
Originally Posted by RudiC
There is some essential info missing in your specification:
- Why does specific_filename=libvclient_release_x64.so.* "not do the job"?What's the error?
The answer for the third question follows.
Code:
specific_filename=libvclient_release_x64.so.*
number=${specific_filename##*[.]}
echo $number

The output of third command is:
Code:
libicudata.so 
libicudata.so.54 
libicui18n.so 
libicui18n.so.54 
libicuio.so 
libicuio.so.54 
libicuuc.so 
libicuuc.so.54 
libvclient_release_x64.so 
libvclient_release_x64.so.740 
libvkernel_release_x64.so 
libvkernel_release_x64.so.740 
libvreport_release_x64.so 
libvreport_release_x64.so.740 
libvshared_release_x64.so 
libvshared_release_x64.so.740

and not the number 740.

Last edited by csanyipal; 08-22-2017 at 01:57 AM..
# 14  
Old 08-21-2017
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?
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