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 February 7th, 2005, 09:44 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

my old program is using cut to get the date of the file such:
for FILE in ATK*
do
file_year=$(echo $FILE| cut -c 13-16)
file_month=$(echo $FILE|cut -c 13-18)
###
echo $file_month --->just as example!
done
where filename is such:
ATK_7B1_WIP_20041116160700.1.xml.dsc
ATK_7B1_WIP_20041116160700.2.xml.dsc
ATK_7B1_WIP_20041116160700.3.xml.dsc
ATK_7B1_WIP_20041116160700.4.xml.dsc

problem is how can i enhance it to all filename?
such:
AIT_7B1_WIP_20050101010101.dsc
ASECL_7B1_WIP_20041209151027.xml.dsc
ASEKR_7B1_WIP_20050101020202.dsc

so i cant use the ' for FILE in ATK* ' rite?
should replace with what?
all the filename will be the same unless the front name:
xxxx_7B1_WIP_20041116160700xxx
help!!!

Reply With Quote
  #2  
Old February 8th, 2005, 02:19 AM
zlutovsky zlutovsky is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Prague, Czech Rep.
Posts: 116 zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 22 h 34 sec
Reputation Power: 6
Quote:
Originally Posted by izza_azhar
my old program is using cut to get the date of the file such:
for FILE in ATK*
do
file_year=$(echo $FILE| cut -c 13-16)
file_month=$(echo $FILE|cut -c 13-18)
###
echo $file_month --->just as example!
done
where filename is such:
ATK_7B1_WIP_20041116160700.1.xml.dsc
ATK_7B1_WIP_20041116160700.2.xml.dsc
ATK_7B1_WIP_20041116160700.3.xml.dsc
ATK_7B1_WIP_20041116160700.4.xml.dsc

problem is how can i enhance it to all filename?
such:
AIT_7B1_WIP_20050101010101.dsc
ASECL_7B1_WIP_20041209151027.xml.dsc
ASEKR_7B1_WIP_20050101020202.dsc

so i cant use the ' for FILE in ATK* ' rite?
should replace with what?
all the filename will be the same unless the front name:
xxxx_7B1_WIP_20041116160700xxx
help!!!



Filter out only the appropirate string of your digits and then you can cut the different fields as usualy. Try this script:

:
while read F; do
DIGITS=$(echo $F |
awk ' { match($0,"WIP_[0-9]+")
print substr($0, RSTART+4, RLENGTH-4)
}
'
)
echo $DIGITS
done <<EOF
AIT_7B1_WIP_20050101010101.dsc
ASECL_7B1_WIP_20041209151027.xml.dsc
ASEKR_7B1_WIP_20050101020202.dsc
EOF

As yu can see, I have used your file names. The script gives you the time stamp only. (Copy and store the script, then chmod +x and run it)

Have fun.

Reply With Quote
  #3  
Old February 8th, 2005, 03:42 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
my version using sed

#!/bin/sh

fname=abc_20050201113355.xx
fname=lskdfldlfgjhlabc_20050201113355.xx

###REM a very generic way
###REM eval `echo $fname|sed 's/.*_\(....\)\(..\)\(..\)\(..\)\(..\)\(..\).*/Y=\1 M=\2 D=\3 h=\4 m=\5 s=\6/'`

###REM this is better, nota: sed does not know the '\d+' notation

eval `echo $fname|sed 's/.*_\([1-9][0-9]\{3\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)\([0-9]\{2\}\).*/Y=\1 M=\2 D=\3 h=\4 m=\5 s=\6/'`

echo year $Y
echo month $M
echo day $D
echo hour $h
echo min $m
echo sec $s

Reply With Quote
  #4  
Old February 9th, 2005, 03:13 AM
zlutovsky zlutovsky is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Prague, Czech Rep.
Posts: 116 zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 22 h 34 sec
Reputation Power: 6
Quote:
Originally Posted by guggach
my version using sed

#!/bin/sh

fname=abc_20050201113355.xx
fname=lskdfldlfgjhlabc_20050201113355.xx

###REM a very generic way
###REM eval `echo $fname|sed 's/.*_\(....\)\(..\)\(..\)\(..\)\(..\)\(..\).*/Y=\1 M=\2 D=\3 h=\4 m=\5 s=\6/'`

###REM this is better, nota: sed does not know the '\d+' notation

eval `echo $fname|sed 's/.*_\([1-9][0-9]\{3\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)\([0-9]\{2\}\).*/Y=\1 M=\2 D=\3 h=\4 m=\5 s=\6/'`

echo year $Y
echo month $M
echo day $D
echo hour $h
echo min $m
echo sec $s


Very clever, handy, faster than awk! But badly readable by a man.

To use awk or sed? It is a matter of taste and of personal skil. The computer time factor today is not too significant, because the saved seconds of computer time are cheaper than hours of programing.

If the program in the future should be administered by another person, I would prefer the awk version because of its better readability.

Regards

Reply With Quote
  #5  
Old February 9th, 2005, 03:42 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
hello zlutovsky
i assume a programmer at least should know regexp
in *nix that's basics
so the long sed expr is really easy to read
awk is a formidable tool, in this case awk has no chance vs sed
because of the way awk is working
awk ... imagine an excel, split and full rows and fields, then work
sed ... read a line, scans cmds and apply eachh cmds on the readed line
as long you DONT need formatting or compilation, sed will be faster
i mean
a+=b; no probls in awk
you sure can convince 'sed' to do it, it's a longer way

Reply With Quote
  #6  
Old February 15th, 2005, 12:01 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
thanks all

i already solve my problem

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 4 hosted by Hostway