- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Capturing a word in a line of text whose placement...
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-29-2005 04:36 AM
06-29-2005 04:36 AM
Capturing a word in a line of text whose placement moves
What I want to do then is to extract just the check number from each line. The problem is that the placement of the check number varies depending on the length of the name, so just using the awk print function doesn't always capture the correct field. Is there a command that I can use to locate the field # so that I can then grab the proceeding check number?
OWNER: 59020 1949 INC CHECK: #185841 06/17/05
OWNER: 30252 1995 INCOME PROGRAM LIMITED CHECK: #185842 06/17/05
OWNER: 12129 A G ANDRIKOPOULOS RESOURCES INC CHECK: #185843 06/17/05
OWNER: 52984 A V M INC CHECK: #185844 06/17/05
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2005 04:40 AM
06-29-2005 04:40 AM
Re: Capturing a word in a line of text whose placement moves
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2005 04:40 AM
06-29-2005 04:40 AM
Re: Capturing a word in a line of text whose placement moves
HTH
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2005 04:52 AM
06-29-2005 04:52 AM
Re: Capturing a word in a line of text whose placement moves
create a file findpos.pl as follows
#!/usr/bin/perl
$a=
$b=index $a, "word3";
printf $b
chmod 755 findpos.pl
echo "word1 word2 word3 word4 word5" | ./findpos.pl
12
hope this helps
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2005 05:12 AM
06-29-2005 05:12 AM
Re: Capturing a word in a line of text whose placement moves
perl -n -e 'if (/#(\d+)/) { print $1,"\n"; }' < myfile
You might want to make the pattern match a bit more foolproof by:
perl -n -e 'if (/CHECK:#(\d+)/) { print $1,"\n"; }' < myfile
The \d+ says match all the digits you can; expressions after the matching string in paren's are assigned $1 $2 ... but we are looking for only the number so there is just one paren'ed pattern. Perl is really pattern matching on steroids. I haven't tested this but if I didn't make no booboo's this here should work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2005 05:25 AM
06-29-2005 05:25 AM
Re: Capturing a word in a line of text whose placement moves
cat file | tr " " "\n" | egrep -i "check|#[0-9]"
Anil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2005 05:30 AM
06-29-2005 05:30 AM
Re: Capturing a word in a line of text whose placement moves
# perl -nle'/CHECK:\s*#(\d+)/ and print$1' file
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2005 05:34 AM
06-29-2005 05:34 AM
Re: Capturing a word in a line of text whose placement moves
cat filename | sed -e "s/\(.*\)CHECK: \#\([0-9]\{1,10\}\) \([0-9].*$\)/\2/"
live free or die
harry d brown jr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2005 07:57 AM
06-29-2005 07:57 AM
Re: Capturing a word in a line of text whose placement moves
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2005 07:57 AM
06-29-2005 07:57 AM