|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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? |
|
#2
|
|||
|
|||
|
in your example
echo atk_wip_2004102345line.logs ¦ sed 's/\(.*\)\([0-9]*[0-9]\)\(.*\)/\2/' |
|
#3
|
|||
|
|||
|
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'?
|
|
#4
|
|||
|
|||
|
sed 's/\(.*_\)\([0-9]*[0-9]\)\(.*\)/\2/'
|
|
#5
|
|||
|
|||
|
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!! |
|
#6
|
|||
|
|||
|
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 |
|
#7
|
|||
|
|||
|
ok
..thanks...done
Last edited by izza_azhar : January 6th, 2005 at 03:04 AM. Reason: ok |
|
#8
|
|||
|
|||
|
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 |
|
#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. |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > split string |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|