UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old December 30th, 2004, 06:27 PM
izza_azhar izza_azhar is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 49 izza_azhar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 33 m 57 sec
Reputation Power: 4
split string

how to split string in a directory.

ex: file name is atk_wip_2004102345line.logs.
how i'm gonna split to just have the date?
=20041023 only?

Reply With Quote
  #2  
Old December 31st, 2004, 04:53 AM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,083 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 19 h 33 m 4 sec
Reputation Power: 9
in your example
echo atk_wip_2004102345line.logs ¦ sed 's/\(.*\)\([0-9]*[0-9]\)\(.*\)/\2/'

Reply With Quote
  #3  
Old January 2nd, 2005, 10:33 PM
izza_azhar izza_azhar is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 49 izza_azhar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 33 m 57 sec
Reputation Power: 4
sorry

it can't work..can i used echo atk_wip_2004102345line.logs | sed 's/\_/ /g' ? but it looks like removind the '_'.how can i display '2004102345'?

Reply With Quote
  #4  
Old January 3rd, 2005, 12:27 AM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,083 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 19 h 33 m 4 sec
Reputation Power: 9
sed 's/\(.*_\)\([0-9]*[0-9]\)\(.*\)/\2/'

Reply With Quote
  #5  
Old January 6th, 2005, 12:39 AM
izza_azhar izza_azhar is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 49 izza_azhar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 33 m 57 sec
Reputation Power: 4
thank

its work..
but i can't passed that value to variable.
ok let say the file name is 7B1_WIP_20041120010436.11497972948866630.xml.dat

surely i can used sed u say just now. there will return
20041120010436 only.

what can do to just have the date?=20041120

do we need to use sed 2 times?
help!!

Reply With Quote
  #6  
Old January 6th, 2005, 01:29 AM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,083 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 19 h 33 m 4 sec
Reputation Power: 9
sed 's/\(.*_\)\([0-9]\{8\}\)\(.*\)/\2/'

??? but i can't passed that value to variable.
VAR=`sed '....'`
echo $VAR

Last edited by guggach : January 6th, 2005 at 01:30 AM. Reason: typo

Reply With Quote
  #7  
Old January 6th, 2005, 02:59 AM
izza_azhar izza_azhar is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 49 izza_azhar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 33 m 57 sec
Reputation Power: 4
ok

..thanks...done

Last edited by izza_azhar : January 6th, 2005 at 03:04 AM. Reason: ok

Reply With Quote
  #8  
Old January 6th, 2005, 03:00 AM
izza_azhar izza_azhar is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 49 izza_azhar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 33 m 57 sec
Reputation Power: 4
it works..

thanks..
but may be u think i'm gonna pass the input variable

actually, i's going to use back the value to compate with currebt date.
let say:
for file in ls ATK*
do
file2=$file | sed 's/\(.*_\)\([0-9]\{8\}\)\(.*\)/\2/'
if $file2 = date +%Y%m%d
then
echo "file updated"
fi
done

-->$file2 means variable passed after sed function perform.

or simple words is..how we use the output of sed function as another input?
sorry..i'm quite dump in this programming language

Reply With Quote
  #9  
Old January 6th, 2005, 06:07 AM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,083 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 19 h 33 m 4 sec
Reputation Power: 9
hi izza
may i kindly invite you to read a (shell) book ?
before writing scripts, think about what you try to do and
the simpliest way to do it.

TODAY=`date +%Y%m%d`
for file in `ls ATK*`
do case $file in *$TODAY*) XX= ;; *) XX=not ;; esac
echo $file $XX updated
done
------------------ an other way
ls ATK*$TODAY* 2>/dev/null && echo UPDATED
-------------------
i let you correct your script, all programming languages are
not trivial, but (bourne)shell is pretty easy, the rest is logic.
in your exp. on every matching filenames
- you start a sed to cut the filename (do it once)
- corollary, the fname could be duplicated !!!
- compute the date (a constant, do it once)
- all this work for what ? on a big directory it could be
a performance issue.

- finally, dont trust the date in the filename, use 'stat()'
in perl, but this is an other && distant chapter.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > split string


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway