![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
| date manipulation | pstanand | Shell Programming and Scripting | 6 | 04-03-2008 11:11 AM |
| Manipulation of Date in Shell | jnanesh.b | Shell Programming and Scripting | 1 | 01-11-2008 01:16 PM |
| Help with log manipulation | StevePace | Shell Programming and Scripting | 3 | 01-31-2006 08:28 PM |
| date manipulation | jalburger | Shell Programming and Scripting | 3 | 05-10-2004 02:09 PM |
| Time/date manipulation | choice | High Level Programming | 1 | 02-01-2002 04:06 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Date Manipulation
I need to achieve the following.....I seached the forum but could not find it...
This is I have in a file... HTML Code:
"CH","TIA","10/27/2006",000590 How do I do it. |
|
||||
|
Code:
$ cat file "CH","TIA","10/27/2006",000590 $ sed 's;.*"\([0-9]*\)/\([0-9]*\)/\([0-9]*\).*;\3\1\2;' file 20061027 Code:
dt=$( sed 's;.*"\([0-9]*\)/\([0-9]*\)/\([0-9]*\).*;\3\1\2;' file )
mv filenm ${dt}"_"filename
|
|
||||
|
if you have Python, here's an alternative
Code:
import os
myfile = "filename"
for line in open("file"):
dt = line.split(",")[2][1:-1].split("/")
newname = "%s%s%s_test.txt" %(dt[2],dt[0],dt[1])
os.rename(myfile,newname) #rename file to new filename with date attachment
|
|
|||||
|
With gawk:
Code:
awk 'FNR==1{gsub(/\"/,"",$3);split($3,dt,"/")}
{print "mv", FILENAME, (dt[3] dt[2] dt[1] "_" FILENAME)|"sh";nextfile}' FS="," inputfile[s]
Code:
awk 'FNR==1{gsub(/\"/,"",$3);split($3,dt,"/")}
{f[FILENAME]=(dt[3] dt[2] dt[1] "_" FILENAME)}END{for(i in f)print "mv",i,f[i]|"sh"}' FS="," inputfile[s]
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|