Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I need help with either sed/awk or something else for unix replacing a set of numbers that is in the 2nd row and 3rd column of a file. these numbers represent a date "073006", I need to add the slashes so it looks like "07/30/06".

You can use 'substr' function of awk.
Do an: awk '{print substr($1,0,2)"/"substr($1,3,2)"/"substr($1,5,2);}'
Hope this helps.
Rais.

couldn't quite get it to work, here's more data, i have file A:
There is a title in this area
Entry Date: 20070629
More lines hereI need to get to 20070629 and change it to read 06/29/07 and then save file A to file B so I can ftp it another server. That's why I was asking how to get to the 2nd row in my file and the 3rd column.
thanks

that almost worked, instead of getting 06/29/07, it made it 20/07/06, also it put slashes through out the file, can I limit it to just put slashes for just that one area? my file has over hundred lines and i need to edit just third line, but i need to make the change in the third line but keep everything just like it is for the first two lines as well as the rest of the file.
thanks again, i really appreciate all the help.

no it will not put slashes throughout because NR==2, which means at record number 2. If you want it to be at third line, use NR==3. $3 means third column, so the example i give only make changes to the 3rd column. as for the date, you just have to substr the correct parts out.I have shown you in the example, so you should be able to apply it ..

Okay, i'm almost there, 070531 when i do my
awk 'NR==1{$6=substr($6,3,4)"/"substr($6,5,6)"/"substr($6,1,2){print}' file gives me 0531/31/07, i can't seem to get rid of that first 31. if I change my 3,4 to 1,2 i get 07/31/07, so why is it that my 3,4 doesn't give me just the 05?

you have to read the awk manual on how to use substr, not just blind experimenting. substr($6,3,4) means get from position 3 and then 4 characters after that. what you need is 2 characters , not 4.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |