- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Help required on setting date variable
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-20-2009 11:28 PM
тАО10-20-2009 11:28 PM
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
Gaby1110
Solved! Go to Solution.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-21-2009 12:11 AM
тАО10-21-2009 12:11 AM
Solutioneval $(locale -k abmon | sed 's/";"//g')
awk -v abmon=$abmon -F, '
NR == 2 {
# print $5
year=substr($5,1,2) + 2000
mon=substr($5,3,2)
day=substr($5,5,2)
print day "-" substr(abmon, 3*(mon)-2, 3) "-" year
}' ETCTRN4010000A.092309.023021001.txt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-21-2009 12:14 AM
тАО10-21-2009 12:14 AM
Re: Help required on setting date variable
x=$(
awk -v abmon=$abmon -F, '
...
}' ETCTRN4010000A.092309.023021001.txt)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-21-2009 02:37 AM
тАО10-21-2009 02:37 AM
Re: Help required on setting date variable
I have created a script named test.sh. Could you please let me know if this is correct?
more test.sh
# get month abbreviations in abmon
eval $(locale -k abmon | sed 's/";"//g')
x=$(
awk -v abmon=$abmon -F, '
NR == 2 {
# print $2
year=substr($2,1,2) + 2000
mon=substr($2,3,2)
day=substr($2,5,2)
print day "-" substr(abmon, 3*(mon)-2, 3) "-" year
}'ETCTRN4010000A.092309.023021001.txt)
Thanks
Gaby1110
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-21-2009 04:08 AM
тАО10-21-2009 04:08 AM
Re: Help required on setting date variable
> Could you please let me know if this is correct?
Why don't you try running it? "Correct" is whatever faithfully produces the desired output without false results in this case. You can't hurt anything by trying!
That said, the last line needs a space added. Instead of:
}'ETCTRN4010000A.092309.023021001.txt)
You should have:
}' ETCTRN4010000A.092309.023021001.txt)
That is, there is one or more whitespaces avter the closing tick for the 'awk' script, before the name of the file you want to process.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-21-2009 05:24 AM
тАО10-21-2009 05:24 AM
Re: Help required on setting date variable
Gaby
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-21-2009 04:39 PM
тАО10-21-2009 04:39 PM
Re: Help required on setting date variable
I would include this at the top of your script:
#!/usr/bin/ksh
(Or sh.)
You initially had field 5 and now you have 2.
Note that once you get it into a variable, you would have to use that variable in your script.
Or you could make this script echo the value and then you can use this script inside other scripts.
So how do you intend to use that script? I assumed you would take my script fragment and insert it into another script.