- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: commands
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
тАО11-13-2006 12:19 PM
тАО11-13-2006 12:19 PM
From the below word
:[rosePink]
i want to remove : [, and ]
i just want to extract rosePink.
How do i do that ?
Thanks,
Shiv
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-13-2006 12:30 PM
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-13-2006 01:09 PM
тАО11-13-2006 01:09 PM
Re: commands
Another way:
# echo "I am :[rosePink] I am" | perl -ne 'print $1 if m%.*\[(.+)\].*%'
# perl -ne 'print $1 if m%.*\[(.+)\].*%' file
Regards!
...JRF...
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-13-2006 01:19 PM
тАО11-13-2006 01:19 PM
Re: commands
is there any other alternative using greg/egrep or awk ?
best regards,
shiv
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-13-2006 01:27 PM
тАО11-13-2006 01:27 PM
Re: commands
echo ":[rosePink]" | awk -F [ '{print $2}' | awk -F ] '{print $1}'
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-13-2006 01:49 PM
тАО11-13-2006 01:49 PM
Re: commands
You wrote, "we don't want to use the word "i am and also don't want to use perl".
First, the example I showed simply extracts the string contained in square brackets --- which was exactly the extent of what you asked.
Second, you never indicated what tools you would accept and what tools you would not. Perl was my choice.
# echo ":[rosePink]"|perl -nle 'print $1 if m%\[(.+)\]%'
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-13-2006 02:23 PM
тАО11-13-2006 02:23 PM
Re: commands
rosePink
Actually, as much as I often think Shiv shoudl use study the man pages a bit more, and just try some stuff to learn, this time he is onto something tricky.
The square brackets are tricky to specify as they are a critical part of regular expression.
As we all know, awk can use a regulare expression as field seperator. And boxed characters are a choicelist of sort. Pick "i" and "o" as seperators and this works...
$ echo :[rosePink] | awk -F [io] '{ print $2}'
seP
Now pick "[" and "]"... no go...
$ echo :[rosePink] | awk -F [[]] '{ print $2}'
Ok, so escape them.... no go...
$ echo :[rosePink] | awk -F [\[\]] '{ print $2}'
Now escape them, and re-order and it works:
$ echo :[rosePink] | awk -F [\]\[] '{ print $2}'
rosePink
At first I though i was battling the shell on top of awk, but even using a tiny awk program you need to take thenm out of order.
$ cat test.awk
BEGIN { FS="[][]" }
{ print "1=" $1 " 2=" $2 " 3=" $3 }
$ echo :[test]aaa | awk -f x.awk
1=: 2=test 3=aaa
grins,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-13-2006 02:51 PM
тАО11-13-2006 02:51 PM
Re: commands
Shiv wrote> i want to remove : [, and ]
taking that original request literally the solution would be:
$ echo :[rosePink] | tr -d :[]
rosePink
Or with symbols:
$ x=:[rosePink]
$ y=$(echo $x | tr -d :[])
$ echo $x " - " $y
:[rosePink] - rosePink
Hein.
- Tags:
- tr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-13-2006 04:45 PM
тАО11-13-2006 04:45 PM
Re: commands
I respect your choice of tools as always.
Best Regards,
Shiv
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-14-2006 09:53 PM
тАО11-14-2006 09:53 PM
Re: commands
this run fine on my Hp-UX11i:
% echo ":[rosePink]"|tr -d [:punct:]
rosePink
HTH,
Art