- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- sed usage for report generation
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
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
10-19-2001 07:59 AM
10-19-2001 07:59 AM
1. lastlog_model
It is a ASCII file that contains stanzas with the last login attributes for users.Each stanza is identified by a use name and contains attributes inthe Attribute=Value form. Each attribute is ended by a new line character, and each stanza is ended by an additional new-line character.
2. report
This is the file I want to generate for system accounting.
I am looking a script which can generate the second file according to the original one, file lastlog_model from AIX, but I know the shell should be same.
Any reply will be really appreciate.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2001 08:29 AM
10-19-2001 08:29 AM
Re: sed usage for report generation
awk '
BEGIN {
FS="\n";
RS="";
OFS=" ";
ORS="\n";
}
{
for (i=1;i<=NF;i++) {
printf "%s ", substr($i,index($i,"=")+1)
}
printf "\n"
}'
HTH
dave
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2001 08:37 AM
10-19-2001 08:37 AM
SolutionTry this. This should work if your input file looks exactly the way you attached.
#!/usr/bin/ksh
if [ $# -ne 1 ]
then
echo "Usage: $0 inputfile"
exit 1
fi
FILE=$1
printf "%-20.30s %-20.20s \n" "user_name" "Time Last Login"
echo ""
for i in `grep -v "=" $FILE`
do
USER=`echo $i|sed 's/://'`
LINE=`sed -n '/'$i'/,/time_last_login/p' $FILE |grep last_login`
UTIME=`echo $LINE|awk '{print $3}'`
printf "%-20.30s %-20.20s \n" "$USER" "$UTIME"
done
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2001 09:02 AM
10-19-2001 09:02 AM
Re: sed usage for report generation
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2001 11:41 AM
10-19-2001 11:41 AM
Re: sed usage for report generation
Your script has a mini problem: there are some comments in the beginning of lastlog_model, the loop(grep -v "=" $FILE) does not filter those comments.
However, I still want to give you 10 points, your script is perfect, thank you so much.
Have a nice weekend.
Shawn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2001 12:04 PM
10-19-2001 12:04 PM
Re: sed usage for report generation
It's simple. You just need to make these modifications.
...
....
fi
FILE=/tmp/file$$
sed '/^*/d' $1 > $FILE (If the comment is with *)
...
..
...
done
rm $FILE
Sorry for the overlook.
-Sri