- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: 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 05:14 PM
05-20-2003 05:14 PM
scripting
I have log file
10117 16/May/2003
10154 16/May/2003
10162 16/May/2003
10181 16/May/2003
I am trying to format the above output to change the month to number ie May to 05 and print the date in mm/dd/yy format as
10162 05/16/2003
10181 05/16/2003
Log file may contain entries for all the months.
I am not very good in scripting. I don't know how to do it.
Any help is appreciated.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2003 06:33 PM
05-20-2003 06:33 PM
Re: scripting
You can get the format you want using this command
date +'%m/%d/%Y'
Use this in your script to replace the existing with the new
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2003 07:05 PM
05-20-2003 07:05 PM
Re: scripting
#!/usr/bin/sh
cat - | while read NUM DATE
do
DT=$(caljd.sh -S "/" $(caljd.sh -i -S "/" -e -c ${DATE}))
echo "${NUM} ${DT}"
done
A search of the Forums should lead you to a copy of caljd.sh - make sure that you get Vrsn 2.10 - it's the latest.
Invoke as caljd.sh -u for full usage.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2003 07:20 PM
05-20-2003 07:20 PM
Re: scripting
Invoke as
awk -f sam.awk /path/to/logfile > /path/to/newlog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2003 05:57 AM
05-23-2003 05:57 AM
Re: scripting
here's a script. It could be made more tricky but since youre not so skilled in script programming I tought this would be quite readable for you.
Save the script as f.ex. ./logfile.sh
remember to set the script to be excecutable:
chmod u+rx ./logfile.sh
And use it like this:
cat logfile | ./logfile.sh
#!/bin/sh
while read FIRSTVALUE DATEVALUE
do
DD="$(echo "$DATEVALUE"|cut -d"/" -f1)"
MM="$(echo "$DATEVALUE"|cut -d"/" -f2)"
YY="$(echo "$DATEVALUE"|cut -d"/" -f3)"
case $MM in
Jan|jan) MM=01
;;
Feb|feb) MM=02
;;
Mar|mar) MM=03
;;
Apr|apr) MM=04
;;
May|may) MM=05
;;
Jun|jun) MM=06
;;
Jul|jul) MM=07
;;
Aug|aug) MM=08
;;
Sep|sep) MM=09
;;
Oct|oct) MM=10
;;
Nov|nov) MM=11
;;
Dec|dec) MM=12
;;
*) print 'Invalid month' >&2
esac
print "$FIRSTVALUE ${MM}/${DD}/${YY}"
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2003 06:09 AM
05-23-2003 06:09 AM
Re: scripting
Add the following lines in the above script (from line 2)
#Define variables for filenames
# remember to change according to your usage.
LOGFILE="/path/to/mylogfile"
NEWLOG="--------/newlog"
# Create pipelines for input/output
exec 3<$LOGFILE
exec 1>$NEWLOG
Then change the "while read" command to be "while read -u3"
This will read from "pipe"=3 as we defined in with the exec command.
To complete you should also do a proper closing of the new file...
Add as a last line:
exec 3>-
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2003 06:30 AM
05-23-2003 06:30 AM
Re: scripting
while read line
do
number=$(echo $line | awk '{print $1}')
day=$(echo $line | awk '{print $2}' | awk -F/ '{print $1}')
month=$(echo $line | awk '{print $2}' | awk -F/ '{print $2}')
year=$(echo $line | awk '{print $2}' | awk -F/ '{print $3}')
if [ "$month" = "Jan" ]
then
mth=01
elif [ "$month" = "Feb" ]
then
mth=02
elif [ "$month" = "Mar" ]
then
mth=03
elif [ "$month" = "Apr" ]
then
mth=04
elif [ "$month" = "May" ]
then
mth=05
elif [ "$month" = "Jun" ]
then
mth=06
elif [ "$month" = "Jul" ]
then
mth=07
elif [ "$month" = "Aug" ]
then
mth=08
elif [ "$month" = "Sep" ]
then
mth=09
elif [ "$month" = "Oct" ]
then
mth=10
elif [ "$month" = "Nov" ]
then
mth=11
elif [ "$month" = "Dec" ]
then
mth=12
fi
echo $number $mth"/"$day"/"$year >> file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2003 06:30 AM
05-23-2003 06:30 AM
Re: scripting
while read line
do
number=$(echo $line | awk '{print $1}')
day=$(echo $line | awk '{print $2}' | awk -F/ '{print $1}')
month=$(echo $line | awk '{print $2}' | awk -F/ '{print $2}')
year=$(echo $line | awk '{print $2}' | awk -F/ '{print $3}')
if [ "$month" = "Jan" ]
then
mth=01
elif [ "$month" = "Feb" ]
then
mth=02
elif [ "$month" = "Mar" ]
then
mth=03
elif [ "$month" = "Apr" ]
then
mth=04
elif [ "$month" = "May" ]
then
mth=05
elif [ "$month" = "Jun" ]
then
mth=06
elif [ "$month" = "Jul" ]
then
mth=07
elif [ "$month" = "Aug" ]
then
mth=08
elif [ "$month" = "Sep" ]
then
mth=09
elif [ "$month" = "Oct" ]
then
mth=10
elif [ "$month" = "Nov" ]
then
mth=11
elif [ "$month" = "Dec" ]
then
mth=12
fi
echo $number $mth"/"$day"/"$year >> file
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2003 06:32 AM
05-23-2003 06:32 AM
Re: scripting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2003 07:24 AM
05-23-2003 07:24 AM
Re: scripting
# cat blah
10117 16/May/2003
10154 16/May/2003
10162 16/May/2003
10181 16/May/2003
# perl -pe'BEGIN{@m{qw(jan feb mar apr may jun jul aug sep oct nov dec)}=("01".."12")}for$m(keys%m){s/\b$m\b/$m{lc$m}/ie}' blah
10117 16/05/2003
10154 16/05/2003
10162 16/05/2003
10181 16/05/2003
#
Enjoy, have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2003 07:27 AM
05-23-2003 07:27 AM
Re: scripting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2003 07:35 AM
05-23-2003 07:35 AM
Re: scripting
Enjoy, have FUN! H.Merijn