The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
mv Filename variable to another filename gzs553 Shell Programming and Scripting 3 04-14-2008 04:19 PM
Report of duplicate files based on part of the filename sudheshnaiyer UNIX for Dummies Questions & Answers 1 12-18-2007 04:31 PM
shortcut for tar cvf - [filename] | gzip > [filename].tar.gz bcamp1973 UNIX for Dummies Questions & Answers 4 12-11-2007 05:45 PM
read a part of filename from the list in the script happyv Shell Programming and Scripting 3 10-20-2006 09:58 AM
Wanted to eliminate numeric part from a filename Sona UNIX for Dummies Questions & Answers 8 07-20-2006 02:49 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-27-2008
flame_eagle flame_eagle is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 16
part of a filename

Hi,

I need to extract only a part of the filenames of some files. The files are named this way :

Code:
.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 :

Code:
find .tap_profile_* | grep -o "[A-Z]\{3\}[0-9]\{2\}$"
  #2 (permalink)  
Old 02-27-2008
bobbygsk bobbygsk is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 90
slight modification to your command
Quote:
find . -name '.tap_profile_*' -print | grep "[A-Z]\{3\}[0-9]\{2\}$"
where "." (dot) specifies the command to find from current directory
  #3 (permalink)  
Old 02-27-2008
flame_eagle flame_eagle is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 16
I'll do the modification later, it never hurt to be more rigorous

Also, to make things clearer, let's say there is a file named ".tap_profile_SIT02old", I don't need it in the resulting file
  #4 (permalink)  
Old 02-27-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,300
Try this with sed:

Code:
find .tap_profile_* | sed 's/.*_\(.*\)/\1/'
Regards
  #5 (permalink)  
Old 02-27-2008
flame_eagle flame_eagle is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 16
Code:
find .tap_profile_*
.tap_profile_DEV07
.tap_profile_DEV07_6.2.1.0
.tap_profile_DEV08
.tap_profile_GFER1
.tap_profile_SIT02
Code:
find .tap_profile_* | sed 's/.*_\(.*\)/\1/'
DEV07
6.2.1.0
DEV08
GFER1
SIT02
That's why I was trying with a regular expression, not that your idea wasn't a good one.

@bobbygsk

I tried your modification, but the result I get aren't the same. It matches a lot more files
  #6 (permalink)  
Old 02-27-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,300
I have not read your 2nd post before I post the solution, try this with awk:

Code:
find .tap_profile_* |awk -F"_" '{print $3}'
Regards
  #7 (permalink)  
Old 02-28-2008
flame_eagle flame_eagle is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 16
Code:
find .tap_profile_* |awk -F"_" '{print $3}'
DEV07
DEV07
DEV08
GFER1
SIT02
I'm still getting results that I don't need (.tap_profile_DEV07_6.2.1.0 should be ignored)
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:19 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0