Operating System - Linux
1820568 Members
1963 Online
109626 Solutions
New Discussion

Need help on date variable

 
Gaby1110
Frequent Advisor

Need help on date variable

Hi,

Need your help.I need to get the date from the second line of a file


[devuser@vfabuser ~]$ head -n2 ETCTRN4010000A.092309.023021001.txt | tail -n1

02,3009483,121000248,1,090922,,,/
[devuser@vfabuser ~]$

If you see above, I need 090922 stored to a variable as ‘22-SEP-2009’

Please help.

Thanks
Gaby
5 REPLIES 5
Goran Koruga
Honored Contributor

Re: Need help on date variable

Hello.

| cut -d',' -f5

Regards,
Goran
Jared Middleton
Frequent Advisor

Re: Need help on date variable

Once you have the initial value (090922) captured in a variable...

# Set var for test below
$ dt="090922"

You can convert the display format using 'date', e.g.:
$ date -d"${dt}" +"%d-%h-%Y"
22-Sep-2009
Goran Koruga
Honored Contributor

Re: Need help on date variable

Doh, I missed the part where you need this in a different format. See above for a solution.

info date

will give you more details how to use this with examples (or info coreutils -> date).

Regards,
Goran
H.Becker
Honored Contributor

Re: Need help on date variable

Just combining what was already said ...

You can write a small script and use a temporary variable to hold the digits, but you can also do this in one line:

dt=$(date -d $(head -n2 ETCTRN4010000A.092309.023021001.txt |tail -n1 |cut -d ',' -f5) +"%d-%h-%Y")
Dennis Handly
Acclaimed Contributor

Re: Need help on date variable

A link to your same question on HP-UX, where you have to work harder:
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1380285