- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Scripting: group fields into columns
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-07-2003 02:25 AM
10-07-2003 02:25 AM
I'm trying to write a script using an Apache access.log file as input.
As most of you know, the log is formatted like:
IPaddress, userid, time, some code, command, return code, someother code all separated by spaces.
My problem is that the command column is a quoted string containing spaces.
How can I interpret that quoted string as one single column or field?
Another way is: How can I access the second field from last?
Thanks
Raynald
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2003 02:33 AM
10-07-2003 02:33 AM
Re: Scripting: group fields into columns
use ''cut -d"," or in awk set the field separator to a comma FS=","
If the command has the potential for imbedded commas then extract the "IPaddress, userid, time, some code" fields first, then "count" the number of commas and extract the "return code, someother code" fields from the right.
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2003 02:33 AM
10-07-2003 02:33 AM
Re: Scripting: group fields into columns
$(NF-2) for the second to last field.
I'm sure you can do something similar in the shell.
What do you want the output to look like ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2003 02:37 AM
10-07-2003 02:37 AM
Re: Scripting: group fields into columns
awk -F\: '{print $2}' < access_log
If you have the entire input line in a shell variable; e.g. ${MYVAR} then
CMDLINE=$(echo ${MYVAR} | awk -F\" '{print $2}')
echo "Command = ${CMDLINE}"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2003 02:41 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2003 02:49 AM
10-07-2003 02:49 AM
Re: Scripting: group fields into columns
Another method I have used sometimes. Pre-process the file and replace the spaces between the quotes with "_".
IFS=\"
while read a b c
do
d=$(echo $b |tr " " "_")
echo $a $d $c
done
then you can handle this field in the tmpfile as a ordinary field.
After doing what you want it is easy to restore the original field with "echo $
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2003 02:04 AM
10-17-2003 02:04 AM
Re: Scripting: group fields into columns
I used a combination: use second to last field $(NF-1) to tally/purge errors then split input command using FS to workfile to analyze how the application is used.
Thanks again.
Raynald