- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Urgent help in scripting
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
Forums
Discussions
Discussions
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
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
05-20-2003 09:00 PM
05-20-2003 09:00 PM
I need to replace the date format in the access log file from
word dd/mm/yy to
word mm/dd/yy
How to accomplish using any one of these tools sed or awk or perl?
Any help is appreciated.
Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2003 09:14 PM
05-20-2003 09:14 PM
Re: Urgent help in scripting
$ sed 's/mm\dd/dd\/mm/'
Regards
Michael
"When I have trouble spelling, it's called fat finger syndrome"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2003 09:31 PM
05-20-2003 09:31 PM
Re: Urgent help in scripting
I think I didn't explain well.
My log file contains data :
user1 15/05/2003
user3 20/04/2003
user1 23/03/2003
Your suggestion just changes the letters mm/dd.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2003 09:46 PM
05-20-2003 09:46 PM
Re: Urgent help in scripting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2003 09:48 PM
05-20-2003 09:48 PM
Re: Urgent help in scripting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2003 09:49 PM
05-20-2003 09:49 PM
Re: Urgent help in scripting
Try this :
cat test|while read u1 u2
do
date1=`echo $u2|cut -f1 -d/ `
date2=`echo $u2|cut -f2 -d/ `
date3=`echo $u2|cut -f3 -d/ `
echo $u1 $date2"/"$date1"/"$date3
done
test is your filename.
regards
mB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2003 10:00 PM
05-20-2003 10:00 PM
Re: Urgent help in scripting
abcd 10/11/03
abcd 10/12/03
abcd 10/13/03
abcd 10/14/03
abcd 10/15/03
abcd 10/16/03
[balajin@redpenguin tmp]$ awk '{a=$1; b=substr($2,0,2);c=substr($2,4,2); d=substr($2,6);print a " " c "/" b d}' a.txt
abcd 11/10/03
abcd 12/10/03
abcd 13/10/03
abcd 14/10/03
abcd 15/10/03
abcd 16/10/03
-balaji
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2003 10:12 PM
05-20-2003 10:12 PM
SolutionThis sed will do it :
input :
user1 15/05/2003
user3 20/04/2003
user1 23/03/2003
sed 's;\([0-9][0-9]\)/\([0-9][0-9]\)\(/[0-9][0-9][0-9][0-9]\);\2/\1\3;'
output :
user1 05/15/2003
user3 04/20/2003
user1 03/23/2003
Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2003 12:19 AM
05-21-2003 12:19 AM
Re: Urgent help in scripting
Another awk example:
while read a b
do
echo $a `echo $b |awk 'BEGIN { FS = "/"; OFS = "/" }
{ print $2,$1,$3 }'`
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2003 03:28 AM
05-21-2003 03:28 AM
Re: Urgent help in scripting
while read line
do
var1=$(echo $line | awk '{print $1}'
var2=$(echo $line | awk '{print $2}' | awk -F/ '{print $1}'
var3=$(echo $line | awk '{print $2}' | awk -F/ '{print $2}'
var4=$(echo $line | awk '{print $2}' | awk -F/ '{print $3}'
echo $var1 $var3"/"$var2"/"$var4 >> newfile
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2003 01:31 PM
05-21-2003 01:31 PM
Re: Urgent help in scripting
You are all masters!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2003 02:38 PM
05-21-2003 02:38 PM
Re: Urgent help in scripting
Yes, i know it, it is too late, but i was traveling the last days. Anywere, this is my answer:
awk -F"[ \t/]" '{printf("%s %s/%s/%s\n",$1,$3,$2,$4)}' logfile
Cheers.
Frank.