- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- how to paser this 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
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-15-2007 11:43 AM
тАО05-15-2007 11:43 AM
I have not script for a while....and need your help again..
say if I have a line like this..
list="Only in /usr/local/bin Only in /usr/lib/bin Only in /home/smith"
I parse that one string into 3 strings such as
Only in /usr/local/bin
Only in /usr/lib/bin
Only in /home/smith
I used to know how to do this...
please help out!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-15-2007 01:13 PM
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-15-2007 01:53 PM
тАО05-15-2007 01:53 PM
Re: how to paser this string
...and if you want a (longer) 'awk' solution:
# echo ${list} | awk '{while (match($0,/Only in [A-Za-z\/]+/)) {S=substr($0,RSTART,RLENGTH);print S;$0=substr($0,RLENGTH)}}'
Regards!
...JRF...
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-15-2007 03:04 PM
тАО05-15-2007 03:04 PM
Re: how to paser this string
Speficifcally... Will a new chunk always start with space+"Only in", or just "Only", or...
$ echo $list | perl -pe 's% (Only in)%\n$1%g'
Only in /usr/local/bin
Only in /usr/lib/bin
Only in /home/smith
If it always starts with whatever the first chunk starts with, and there is a space, then you could use:
$ echo $list | perl -pe '$x=substr($_,0,5); s/\s$x/\n$x/g'
Only in /usr/local/bin
Only in /usr/lib/bin
Only in /home/smith
$
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-16-2007 05:48 AM
тАО05-16-2007 05:48 AM
Re: how to paser this string
I would like to try the perl command, but, I am still not getting this one quite right, please help me.
the input is
Only in /usr/local/bin: a.config Only in /usr/lib/bin: b.conf Only in /home/smith: c.conf
Notice there is no "space" before "Only in", but now, I add the file name...how do I include the file name....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-16-2007 05:56 AM
тАО05-16-2007 05:56 AM
Re: how to paser this string
OK, given:
# list="Only in /usr/local/bin: a.config Only in /usr/lib/bin: b.conf Only in /home/smit
h: c.conf"
...then:
# echo ${list} | perl -nle 'print $1 while /(Only in\s+\S+\s\S+)/g'
...yields:
Only in /usr/local/bin: a.config
Only in /usr/lib/bin: b.conf
Only in /home/smith: c.conf
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-16-2007 06:36 AM
тАО05-16-2007 06:36 AM
Re: how to paser this string
...and for similar changes to the 'awk':
# echo ${list} | awk '{while (match($0,/Only in ([A-Za-z\/\:]+ [A-Za-z\.]+ *)/)) {S=substr($0,RSTART,RLENGTH);print S;$0=substr($0,RLENGTH)}}'
Note, of course, that with the 'awk' snippet, filenames containing numbers or special characters would fail the match. I'll leave that as an exercise for you!
The Perl solutions using '\s' for a whitespace and '\S' for a nonwhitespace is easier (as Perl is!). For that matter, Hein's solutions are quite elegant too, and required no changes.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-16-2007 07:36 AM
тАО05-16-2007 07:36 AM
Re: how to paser this string
# echo $list | awk -F"Only" '{for(i=1;i<=NF;++i) if($i) print FS$i}'
~cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-16-2007 07:45 AM
тАО05-16-2007 07:45 AM
Re: how to paser this string
That's a VERY elegant 'awk' solution! Shorter AND sensitive only to matching the keyword "Only". I always learn better ways with 'awk' and 'sed' reading your contributions.
/* NO POINTS for this post, please */
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-16-2007 07:57 AM
тАО05-16-2007 07:57 AM
Re: how to paser this string
:D