- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Scripting
Operating System - HP-UX
1757146
Members
2337
Online
108858
Solutions
Forums
Categories
Company
Local Language
юдл
back
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
юдл
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- 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
тАО01-26-2009 12:51 PM
тАО01-26-2009 12:51 PM
I am writing a script and I've hit the wall with this idea. Before I do, I just wanted to see if I can do this, if not, I have other ideas. I have a file that looks like this:
-----------------------------------------------------------
Audit mode : Login-Success, Failure, Login-Failure
Group connections :
Group Owner Date Time Type
cweis eacnobody 25-Jul-2008 23:19 Regular
eiisgw eacnobody 25-Jul-2008 23:19 Regular
Owner : eacnobody (USER )
Inactive days : 0
Password interval : 0
Full name : Richard El
Create time : 25-Jul-2008 23:18
Update time : 23-Feb-2008 03:05
Updated by : 7972
(localhost)
Data for USER '336'
----------------------------------------------------------------------------------------------------------------------
Audit mode : Login-Success, Failure, Login-Failure
Group connections :
Group Owner Date Time Type
cweis eacnobody 25-Jul-2008 23:19 Regular
eiisgw eacnobody 25-Jul-2008 23:19 Regular
Owner : eacnobody (USER )
Inactive days : 0
Password interval : 0
Full name : Rich Oll
Create time : 25-Jul-2008 23:18
Update time : 23-Feb-2008 03:05
Updated by : u672
(localhost)
Data for USER 'u036e'
-----------------------------------------------------------
Instead of reading in the entire file, can I use the ---'s as a record seperator? so from --- to --- is one file and so on?
-----------------------------------------------------------
Audit mode : Login-Success, Failure, Login-Failure
Group connections :
Group Owner Date Time Type
cweis eacnobody 25-Jul-2008 23:19 Regular
eiisgw eacnobody 25-Jul-2008 23:19 Regular
Owner : eacnobody (USER )
Inactive days : 0
Password interval : 0
Full name : Richard El
Create time : 25-Jul-2008 23:18
Update time : 23-Feb-2008 03:05
Updated by : 7972
(localhost)
Data for USER '336'
----------------------------------------------------------------------------------------------------------------------
Audit mode : Login-Success, Failure, Login-Failure
Group connections :
Group Owner Date Time Type
cweis eacnobody 25-Jul-2008 23:19 Regular
eiisgw eacnobody 25-Jul-2008 23:19 Regular
Owner : eacnobody (USER )
Inactive days : 0
Password interval : 0
Full name : Rich Oll
Create time : 25-Jul-2008 23:18
Update time : 23-Feb-2008 03:05
Updated by : u672
(localhost)
Data for USER 'u036e'
-----------------------------------------------------------
Instead of reading in the entire file, can I use the ---'s as a record seperator? so from --- to --- is one file and so on?
UNIX IS GOOD
Solved! Go to Solution.
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-26-2009 03:32 PM
тАО01-26-2009 03:32 PM
Re: Scripting
>Instead of reading in the entire file
You have to read the file, nothing will seek for you.
>can I use the "---"s as a record separator?
No, you must read every record and then recognize the "---" lines.
Using RS="-" in awk fails because you use "-" in your dates and text.
You can check for lines with "---" in awk to do whatever you want.
What are you really trying to do with your file?
You have to read the file, nothing will seek for you.
>can I use the "---"s as a record separator?
No, you must read every record and then recognize the "---" lines.
Using RS="-" in awk fails because you use "-" in your dates and text.
You can check for lines with "---" in awk to do whatever you want.
What are you really trying to do with your file?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-26-2009 09:29 PM
тАО01-26-2009 09:29 PM
Solution
>> Instead of reading in the entire file, can I use the ---'s as a record seperator? so from --- to --- is one file and so on?
May we assume you meant 'one line', not 'one file' ?
Yes, tools like AWK and PERL are happy to accept alternative line terminators = "RECORD SEPERATORS".
Witness, for the sample data presented:
$ awk 'BEGIN { } END { print NR }' tmp.txt
33
$ awk 'BEGIN { RS="\n--" } END { print NR }' tmp.txt
3
Often there are minor glitches for the first and/or last seperator.
Personally I often prefer the 'hunt and gather' technique. Hunt for recognizable handles and gather what goes with that.
I recently posted an example in:
http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=1306454
Not knowing what problem you are really trying to solve, I'm guessing that in your case that could look like:
$ awk '/^Fu/{name=$3 " " $4 " " $5} /^Update t/{date=$4} /^Da/{ print $4, date, name }' tmp.txt
'336' 23-Feb-2008 : Richard El
'u036e' 23-Feb-2008 : Rich Oll
Or...
$ awk 'BEGIN {FS=": "} /^Fu/{n=$2} /^Update t/{d=$2} /^Da/{ print $0, d, n;n=d="" }' tmp.txt
Data for USER '336' 23-Feb-2008 03:05 Richard El
Data for USER 'u036e' 23-Feb-2008 03:05 Rich Oll
Enjoy!
Hein.
May we assume you meant 'one line', not 'one file' ?
Yes, tools like AWK and PERL are happy to accept alternative line terminators = "RECORD SEPERATORS".
Witness, for the sample data presented:
$ awk 'BEGIN { } END { print NR }' tmp.txt
33
$ awk 'BEGIN { RS="\n--" } END { print NR }' tmp.txt
3
Often there are minor glitches for the first and/or last seperator.
Personally I often prefer the 'hunt and gather' technique. Hunt for recognizable handles and gather what goes with that.
I recently posted an example in:
http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=1306454
Not knowing what problem you are really trying to solve, I'm guessing that in your case that could look like:
$ awk '/^Fu/{name=$3 " " $4 " " $5} /^Update t/{date=$4} /^Da/{ print $4, date, name }' tmp.txt
'336' 23-Feb-2008 : Richard El
'u036e' 23-Feb-2008 : Rich Oll
Or...
$ awk 'BEGIN {FS=": "} /^Fu/{n=$2} /^Update t/{d=$2} /^Da/{ print $0, d, n;n=d="" }' tmp.txt
Data for USER '336' 23-Feb-2008 03:05 Richard El
Data for USER 'u036e' 23-Feb-2008 03:05 Rich Oll
Enjoy!
Hein.
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP