- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- getline and format in awk
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
Discussions
Discussions
Forums
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
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-01-2008 03:24 AM
тАО05-01-2008 03:24 AM
I want to search a list of installed files (AIX) and I find that the list is not consistent with $1 being the software and $2 being the version. Sometimes in the list $2 in on the next line:
ldap.client.adt 5.2.0.0 COMMITTED Directory Client SDK
ldap.client.rte 5.2.0.0 COMMITTED Directory Client Runtime (No
SSL)
ldap.max_crypto_client.adt
5.2.0.0 COMMITTED Directory Client SDK
ldap.max_crypto_client.rte
5.2.0.0 COMMITTED Directory Client Runtime (SSL)
so I thought I could solve this using getline which I can if I search the pattern and run the below command:
# lslpp -l |awk '/ldap.max/ {(x = $0);getline;print x,$1}'
ldap.max_crypto_client.adt 5.2.0.0
ldap.max_crypto_client.rte 5.2.0.0
but if I search multiple string and check that if $2 is equal to null I get a strange output:
# lslpp -l |egrep "ldap|gsk"
gskak.rte 6.0.5.41 COMMITTED AIX Certificate and SSL Base
gskta.rte 7.0.4.14 COMMITTED AIX Certificate and SSL Base
ldap.client.adt 5.2.0.0 COMMITTED Directory Client SDK
ldap.client.rte 5.2.0.0 COMMITTED Directory Client Runtime (No
ldap.max_crypto_client.adt
ldap.max_crypto_client.rte
ldap.client.rte 5.2.0.0 COMMITTED Directory Client Runtime (No
# lslpp -l |awk '/ldap|gsk/ {if ($2 == "")(x = $0);getline;print x,$1}'
Runtime
Runtime
ldap.client.rte
ldap.max_crypto_client.adt 5.2.0.0
ldap.max_crypto_client.rte 5.2.0.0
ldap.max_crypto_client.rte SSL)
any ideas?
Thanks
Chris
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-01-2008 03:47 AM
тАО05-01-2008 03:47 AM
Re: getline and format in awk
Using your data:
# awk '/ldap|gsk/ {if (NF==1){next} else {print $1,$2}}' file
gskak.rte 6.0.5.41
gskta.rte 7.0.4.14
ldap.client.adt 5.2.0.0
ldap.client.rte 5.2.0.0
ldap.client.rte 5.2.0.0
Isn't that what you want?
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-01-2008 04:03 AM
тАО05-01-2008 04:03 AM
SolutionSorry, I used the "strange output" from your first approximation as my input.
Using this:
# cat .myinput
ldap.client.adt 5.2.0.0 COMMITTED Directory Client SDK
ldap.client.rte 5.2.0.0 COMMITTED Directory Client Runtime (No
SSL)
ldap.max_crypto_client.adt
5.2.0.0 COMMITTED Directory Client SDK
ldap.max_crypto_client.rte
5.2.0.0 COMMITTED Directory Client Runtime (SSL)
...and:
# awk '/ldap|gsk/ {if (NF==1){x=$0;getline;print x,$1} else {print $1,$2}}' ./myfile
ldap.client.adt 5.2.0.0
ldap.client.rte 5.2.0.0
ldap.max_crypto_client.adt 5.2.0.0
ldap.max_crypto_client.rte 5.2.0.0
Regards! [ENOCOFFEE]
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-01-2008 04:13 AM
тАО05-01-2008 04:13 AM
Re: getline and format in awk
it works a treat James ...
Thanks again.
Chris. (MORECOFEE)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-02-2008 12:45 AM
тАО05-02-2008 12:45 AM
Re: getline and format in awk
(I'm not sure why you used ()?)
getline will also let you input into a variable:
{ getline second; print $0, second }
But I suppose if you want $1, you need to do it your way.