- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- extract data from a "," delimitted string
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
06-03-2008 04:51 AM
06-03-2008 04:51 AM
I run a command and the output looks like this:
name=SERV-xadr-99-59-SN11D0FFF,type_model=9119-590,serial_num=51D0F5F,ipaddr=1.1.1.252,ipaddr_secondary=1 ,etc,etc
I am interested in extracting different fields from this output however for this thread I want to display:
SERV-xadr-99-59-SN11D0FFF from name=SERV-xadr-99-59-SN11D0FFF
I have attempted this by using awk and match with no results:
`$sshcmd` |awk -F ',' '{match($1, "name=[^\,]*")}{name = substr($0, RSTART, RLENGHT)};{print name}'
any ideas or a better method?
thanks
Chris.
Solved! Go to Solution.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2008 05:05 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2008 05:15 AM
06-03-2008 05:15 AM
Re: extract data from a "," delimitted string
It didnt work so I read a bit and found out how to use split more effectively and:
`$sshcmd` |awk -F ',' '{split($1,a,"=");print a[2]}'
much appreciated.
Chris.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2008 05:19 AM
06-03-2008 05:19 AM
Re: extract data from a "," delimitted string
like this to count them all. Which program
would you like to use?
> any ideas [...]
"sed"?
td192> echo $name | sed -e 's/\,.*//'
SERV-xadr-99-59-SN11D0FFF
echo $name | sed -e 's/[^,]*\,\([^,]*\)\,.*/\1/'
type_model=9119-590
echo $name | sed -e 's/[^,]*\,[^,]*\,\([^,]*\)\,.*/\1/'
serial_num=51D0F5F
td192> echo $name | sed -e 's/[^,]*\,[^,]*\,[^,]*\,\([^,]*\)\,.*/\1/'
ipaddr=1.1.1.252
> [...] or a better method?
Better? Define good.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2008 05:24 AM
06-03-2008 05:24 AM
Re: extract data from a "," delimitted string
both methods work in different ways and I can make use off all the examples given ...
Chris.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2008 05:31 AM
06-03-2008 05:31 AM
Re: extract data from a "," delimitted string
> It didnt work ...
Oh, you are running AIX :-)
Yes, HP-UX will allow either :
split($1,a,"=")
OR:
split($1,a,/=/);
...whereas on AIX (which I have too) only the first form is correct.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2008 11:16 PM
06-03-2008 11:16 PM
Re: extract data from a "," delimitted string
That will be good to know as I also operate on HPUX and Linux and have noticed some suttle differences with that.
Chris.