awk/sed to search & replace data in first column

Hi All,

I need help in manipulating the data in first column in a file.

The sample data looks like below,

Mon Jul 18 00:32:52 EDT 2011,NULL,UAT
Jul 19 2011,NULL,UAT

1] All field in the file are separated by ","
2] File is having weekly data extracted from database
3] For eg. Consider week from Jul 18 2011 To Jul 24 2011

Here I would like to search for date pattern as "Jul 18", "Jul 19","Jul 20" so on & replace it with "Jul 18 2011" type pattern.

Could you pls help me.

Thanks.

The source file format is strange.

in your sample, there are two different dates displayed.

Mon Jul 18 00:32:52 EDT 2011
Jul 19 2011

I think Mon Jul 18 00:32:52 EDT 2011,NULL,UAT is input and the other line is output.

But anyway do you have GNU date? And what system do you use if you not?

Yes, I have these 2 date patterns in my input file & wanted to convert it to "Jul 18 2011" pattern.

I am using Solaris 8.

Ok, you do not have GNU date and you have two patterns in your input file. You want that there is only one pattern.

Mon Jul 18 00:32:52 EDT 2011,NULL,UAT # changes to Jul 18 2011,NULL,UAT
Jul 19 2011,NULL,UAT # not changes

Yes?

---------- Post updated at 11:53 AM ---------- Previous update was at 11:49 AM ----------

You don't need and date command if I'm right about pattern but it's just a habit (maybe bad one) to ask about it any time when I see questions about date manipulations.

yazu ... Yes, your understanding is very right, please help.

Try:

sed 's/^\(...\) \(...\) \([0-9][0-9]\).*2011/\2 \3 2011/' INPUTFILE

It works only for 2011 year but it's easy enough to fix this.

PS And you should'n have other "2011" in your strings.

1 Like

Yazu ... this is awesome ... worked perfectly !!!

Thanks a lot for help.

One thing ... If possible can you explain in brief how this works ?

Well... English in not my native language.:frowning: And I really can't explain as sed works better than, for example, here: Sed - An Introduction and Tutorial