- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: get a string in a line
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
07-06-2005 08:48 PM
07-06-2005 08:48 PM
get a string in a line
how to get a string in a line hp ux?
'i want to solve this problem' and i want to get 'solve' but how?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2005 08:51 PM
07-06-2005 08:51 PM
Re: get a string in a line
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2005 09:05 PM
07-06-2005 09:05 PM
Re: get a string in a line
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2005 09:19 PM
07-06-2005 09:19 PM
Re: get a string in a line
if you simply want to get a line in a file, use a grep command, it's a simplier way!!
i.e.
grep test file
(if you want to search a string with a test word)
enjoy
Giacomo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2005 09:19 PM
07-06-2005 09:19 PM
Re: get a string in a line
awk '{ print $4 }'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2005 10:19 PM
07-06-2005 10:19 PM
Re: get a string in a line
and STRING IS: 'solve'
so how can i get these string?
note: i just want to get the string 'solve'
i dont want to get line (grep command is not suitable for this question)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2005 10:35 PM
07-06-2005 10:35 PM
Re: get a string in a line
echo "i want to solve this problem" | sed '/solve/!d;s/^.*solve.*/solve/'
or
echo "i want to solve this problem" | grep 'solve' | sed '/solve/!d;s/^.*solve.*/solve/'
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2005 10:36 PM
07-06-2005 10:36 PM
Re: get a string in a line
echo "i want to solve this problem" | awk '/solve/ { print "solve";}'
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2005 10:47 PM
07-06-2005 10:47 PM
Re: get a string in a line
If you want to search for strings in plain text files you can use "grep -q".
-q (Quiet) Do not write anything to the standard
output, regardless of matching lines. Exit
with zero status upon finding the first
matching line. Overrides any options that
would produce output.
Then you can use an "if" condition to print out anything you want depending on hit/non hit.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2005 10:54 PM
07-06-2005 10:54 PM
Re: get a string in a line
if the word "solve" is always on the fourth position, than:
grep solve file| awk '{print $4}'
regards,
Giacomo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2005 11:27 PM
07-06-2005 11:27 PM
Re: get a string in a line
echo "i want to solve this problem" | awk '{ print $4 }'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2005 11:27 PM
07-06-2005 11:27 PM
Re: get a string in a line
and firstly i want to find 'May 13 2003' string in this text and after i want to clear the lines which, dates are before 'May 13 2003'
Thank you again so much
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2005 11:49 PM
07-06-2005 11:49 PM
Re: get a string in a line
try this slightly reused awk statement:
# awk '/May 13/,/\$/' orgfile > newfile
and then
# diff orgfile newfile
to check if it is ok.
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2005 11:52 PM
07-06-2005 11:52 PM
Re: get a string in a line
## CODE ###
FILENAME=testfile
LINE=$(grep -n 'May 13.*2003' $FILENAME | cut -d':' -f1)
tail -f +${LINE} $FILENAME
##
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2005 12:55 AM
07-07-2005 12:55 AM
Re: get a string in a line
awk '{ print $(NF-3),$(NF-2),$(NF-1),$NF }' file
Once you have the timestamps you will need to do some coding where you compare the year, then month, then day.
David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2005 02:54 AM
07-07-2005 02:54 AM
Re: get a string in a line
lt09:/home/merijn 102 > grep -c -w merijn /etc/passwd
1
lt09:/home/merijn 103 > grep -c -w merlijn /etc/passwd
0
lt09:/home/merijn 104 >
Since you want returned something you know, it doesn't matter if you get that word or "1"
If you *do* mind, try this:
sh-3.00$ var=merijn
sh-3.00$ grep -q -w $var /etc/passwd && echo $var
merijn
sh-3.00$ var=merlijn
sh-3.00$ grep -q -w $var /etc/passwd && echo $var
sh-3.00$
Enjoy, Have FUN! H.Merijn