- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: ksh script function extract line number
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-04-2003 06:47 AM
07-04-2003 06:47 AM
Re: ksh script function extract line number
So far the proposals work for "Statistics" but not for "Statistics ( 2K)".
Franky
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2003 06:49 AM
07-04-2003 06:49 AM
Re: ksh script function extract line number
I rememberd your earlier remark and had already tried this with the similar error :
syntax error The source line is 1.
The error context is
>>> /Statistics <<<
awk: Quitting
The source line is 1.
Franky
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2003 06:52 AM
07-04-2003 06:52 AM
Re: ksh script function extract line number
I got the same error on my workstation. The script work however worked fine!
#! /bin/ksh
function getLineNr {
# $1 search string
awk '/'$1'/{print NR}' myfile
}
TEST="Statistics ( 2K)"
ln=`getLineNr $TEST`
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2003 06:56 AM
07-04-2003 06:56 AM
Re: ksh script function extract line number
This means that a search for Statistics(2K) would work but that a search for Statistics (2K) would fail. The script I posted which uses parsing a $TEST instead of "Statistics (2K)" works however
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2003 07:02 AM
07-04-2003 07:02 AM
Re: ksh script function extract line number
With your ' $TEST ' proposal, I can run the script without errors but it returns a wrong result.
I need line number. In the test it returns 3 line numbers, eg for the following lines :
! Statistics------------------------------------------------------------------
! Statistics ( 2K) -----------------------------------------------------------
! Statistics ( 4K) -----------------------------------------------------------
Franky
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2003 07:11 AM
07-04-2003 07:11 AM
Re: ksh script function extract line number
I combined your escaping remark with the $TEST remark from Dagmar.
$TEST="Statistics \( 2K\)"
The script runs without errors but with same wrong results.
Franky
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2003 07:13 AM
07-04-2003 07:13 AM
Re: ksh script function extract line number
and try to escape also the space :)
Massimo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2003 07:15 AM
07-04-2003 07:15 AM
Re: ksh script function extract line number
you get and error because the expansion lead to
getliner Statistics (2k)
and your function gets only the "statistics part.
Massimo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2003 07:19 AM
07-04-2003 07:19 AM
Re: ksh script function extract line number
#! /bin/ksh
getLineNr () {
# $1 search string
grep -n "$@" monitor_dmfcache.tmp | sed -e 's/:.*//'
}
ln=`getLineNr "Statistics ( 2K)"`
echo $ln
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2003 07:19 AM
07-04-2003 07:19 AM
Re: ksh script function extract line number
Escaping also the second space give us the same (wrong) result.
Escaping the first space give us an error :
syntax error The source line is 1.
The error context is
/Statistics\/{ print >>> NR} <<<
awk: Quitting
The source line is 1.
Franky
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2003 07:21 AM
07-04-2003 07:21 AM
Re: ksh script function extract line number
put double quotes around $1
awk '/'"$1"'/{print NR}' myfile
need line number. In the test it returns 3 line numbers
add a "-" to the end of your seach string, i.e. Statistics-
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2003 07:25 AM
07-04-2003 07:25 AM
Re: ksh script function extract line number
ln=$(getLineNR "Statistics ( 2K)")
instead of
ln=`getLineNr "Statistics ( 2K)"`
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2003 07:29 AM
07-04-2003 07:29 AM
Re: ksh script function extract line number
Nice try but got the following errors :
grep: can't open \(
grep: can't open 2K\)
Franky
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2003 07:29 AM
07-04-2003 07:29 AM
Re: ksh script function extract line number
This one outputs only one line (the correct one)!!!
#! /bin/ksh
function getLineNr {
# $1 search string
awk '/'$1'/{print NR}' myfile
}
TEST="Statistics/&&/(2K)"
ln=`getLineNr $TEST`
echo $ln
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2003 07:34 AM
07-04-2003 07:34 AM
Re: ksh script function extract line number
Your first remark did not gave other results.
The second one return in similar errors.
Thanks anyhow for helping me.
Franky
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2003 07:34 AM
07-04-2003 07:34 AM
SolutionThe script below is even better. It wil stop after it has printed the first line number where Statistics (2k) can be found. The previous would print 2 lines if Statistics (2K) occurs two time in the file which we analyze.
#! /bin/ksh
function getLineNr {
# $1 search string
awk '/'$1'/{print NR;exit 1}' myfile
}
TEST="Statistics/&&/(2K)"
ln=`getLineNr $TEST`
echo $ln
~
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2003 07:34 AM
07-04-2003 07:34 AM
Re: ksh script function extract line number
Modifying Ian's answer
#! /bin/ksh
getLineNr () {
# $1 search string
egrep -n "$1" monitor_dmfcache.tmp | awk -F: {print $1 }
}
ln=`getLineNr "Statistics.*2K"`
echo $ln
Massimo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2003 07:37 AM
07-04-2003 07:37 AM
Re: ksh script function extract line number
awk -v string="$1" '{
if ( $0 ~ string ) print NR;
}' yourFile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2003 07:43 AM
07-04-2003 07:43 AM
Re: ksh script function extract line number
I am trying out every one's proposals in FIFO and Dagmar has given me the solution that worked first.
Dagmar,
Good job.
can you explain to me the /&&/ stuff ?
I might need it for other strings.
To the other participants : thanks a many many many lot for your help. This was exciting.
I learned lot.
I will review the other suggestions also (and assign points if usefull).
Again thanks a lot.
Franky
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2003 07:56 AM
07-04-2003 07:56 AM
Re: ksh script function extract line number
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2003 08:01 AM
07-04-2003 08:01 AM
Re: ksh script function extract line number
Thanks for the update.
Franky
- « Previous
-
- 1
- 2
- Next »