- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- usinf sed
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
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
03-06-2005 09:32 PM
03-06-2005 09:32 PM
I'll need to extract data from the following field "WJV82LV83A1.ICZ34K.ws". The data I need is captured between W and the . , i.e. JV82LV83A in this case. as the data may differ in lenght i tried using a combo of awk and sed to do it.. but the script got quite bulky though it did the job., Is there a easier way. I'll need to reduce the speed and alot of data to capture. any advise?
thank u
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2005 09:42 PM
03-06-2005 09:42 PM
Re: usinf sed
echo "WJV82LV83A1.ICZ34K.ws"|awk -F"." '{print $1}'|cut -c2-
Best regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2005 09:53 PM
03-06-2005 09:53 PM
Re: usinf sed
Use the SHELL variable IFS and cut
Or cut with the -d option if the
data field format is stable
echo "WJV82LV83A1.ICZ34K.ws". |cut -f1 -d"."|cut -f2 -d"\""
Steve Steel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2005 10:09 PM
03-06-2005 10:09 PM
Re: usinf sed
echo "WJV82LV83A1.ICZ34K.ws"| awk -F"." '{ print substr($1,2); }'
HTH.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2005 10:10 PM
03-06-2005 10:10 PM
Re: usinf sed
Assuming you always want to drop the first character and keep everything after it up until the first dot (.) then:
str1="WJV82LV83A1.ICZ34K.ws"
tmp=${str1#?}
echo $tmp
JV82LV83A1.ICZ34K.ws
str2=${tmp%%.*}
echo $str2
JV82LV83A1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2005 10:13 PM
03-06-2005 10:13 PM
Re: usinf sed
echo "WJV82LV83A1.ICZ34K.ws"| sed 's/^W\(.*\).I.*/\1/'
HTH.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2005 10:17 PM
03-06-2005 10:17 PM
Re: usinf sed
Thanks for the input, my case is alittle more troublesome, as the I only want the data between W and the 1, and as the number of characters for the data differs from time to time it may be alittle difficult to achieve. I have tried using a script to do it.. but its really bulky.. do u guys have any idea?
Thank u!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2005 10:20 PM
03-06-2005 10:20 PM
Re: usinf sed
If you just want everything between (but not including) the fiorst character on the line, and the last character before the first dot, then:
str1="WJV82LV83A1.ICZ34K.ws"
tmp=${str1#?}
echo $tmp
JV82LV83A1.ICZ34K.ws
str2=${tmp%%?.*}
echo $str2
JV82LV83A
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2005 11:33 PM
03-06-2005 11:33 PM
Re: usinf sed
Here is yest another awk solution:
echo WJV82LV83A1.ICZ34K.ws | awk '{print substr($0,2,index($0,".")-2)}'
Or if the W is not not really only the first character as sugggested, but the fist W then:
echo WJV82LV83A1.ICZ34K.ws | awk '{w=index($0,"W")+1;print substr($0,w,index($0,".")-w)}'
With perl, you don't get the 'newline'.
It could look like:
echo WJV82LV83A1.ICZ34K.ws | perl -ne 'print $1 if (/W([^.]+)/)'
the ERE says: When you see a W, start to remember "(" one or more "+" non-periods "^."
In this case it looks like you could also write:
echo WJV82LV83A1.ICZ34K.ws | perl -ne 'print $1 if (/W([A-Z0-9]+)/)'
Here the ERE says: one or more characters from the A-Z range or 0-9 range.
With a perl solution you cn often do much more of the final processing all rigt there in perl.
Anyway... what specification detail are we missing?
Cheers,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2005 12:37 AM
03-07-2005 12:37 AM
Re: usinf sed
sorry for the trouble..
thank u!!
Henry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2005 12:45 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2005 12:59 AM
03-07-2005 12:59 AM
Re: usinf sed
thanks guys!!