If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > removing strings from filename

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-08-04, 09:10
aliyesami aliyesami is offline
Registered User
 
Join Date: Jun 2003
Posts: 29
removing strings from filename

if I have filenames like this k_tape_dis_06082004.txt , how can I remove the date string appearing in there using KsH ? so the file should look like
k_tape_dis.txt
Reply With Quote
  #2 (permalink)  
Old 06-08-04, 09:31
vgersh99 vgersh99 is offline
Registered User
 
Join Date: Apr 2004
Location: Boston, MA
Posts: 325
Code:
#!/bin/ksh

file='k_tape_dis_06082004.txt'

echo "file->[${file}] changed->[$(echo "${file}" | sed -e 's/^\(.*\)_\([0-9][0-9]*\)\(.*\)/\1\3/g')]"
Reply With Quote
  #3 (permalink)  
Old 06-08-04, 09:38
vgersh99 vgersh99 is offline
Registered User
 
Join Date: Apr 2004
Location: Boston, MA
Posts: 325
..... with the ksh's builtins:

Code:
#!/bin/ksh

file='k_tape_dis_06082004.txt'

echo "file->[${file}] changed->[${file%%_${file##*_}}.${file##*.}]"
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On