- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Query on the file
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
тАО03-03-2003 10:28 AM
тАО03-03-2003 10:28 AM
I have a comma delimited file in which the first field is a key field. I need to do something equivalent to the following in unix.
select count(*) from
The start and end values could be anything (except that end value is always greater). I need to split the file depending on the number i get from above.
In addition to the count if I get the line numbers of the records for the start and end that would be great.
Something worth mentioning here is the start and end value may or may not be in the file.
For example if below is the file
201,34934....
204,39438...
207,983493...
210,03943...
220,0983.....
If my start and end values are 202 and 215. The result needs to be 3 for the count and 2 and 4 for the line numbers.
Thank you very much for you help.
Yours Sincerely,
Chandra
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-03-2003 10:47 AM
тАО03-03-2003 10:47 AM
Solution#!/opt/perl/bin/perl
#
$begVAL=$ARGV[0];
$endVAL=$ARGV[1];
$filename=$ARGV[2];
open(fileptr,"<$filename");
#
$begno=0;
$endno=0;
$lineno=0;
#
while (
$lineno += 1;
($fld1val, $fldrst) = split(/,/);
if (( $begVAL <= $fld1val ) && ( $begno == 0 )) {
$begno = $lineno;
}
if ( $endVAL >= $fld1val ) { $endno=$lineno; }
}
print "first is $begno\n";
print "last is $endno\n";
print "num lines is ",$endno-$begno+1,"\n";
./someperl.pl 202 215 ./numlist.txt
first is 2
last is 4
num lines is 3
#
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-03-2003 11:07 AM
тАО03-03-2003 11:07 AM
Re: Query on the file
Create an awk script, my.awk
BEGIN {
tot = 0
start = -1
end = -1
}
{
val = $1 + 0
if ((val >= lo) && (val <= hi))
{
++val
if ((start < 0) && (val == lo)) start = NR
if (val == hi) end = NR
}
}
END {
printf("%d lines found ",tot)
if (start >= 0) printf("Starting line %d ",start)
if (end >= 0) printf("Last key found %d",end)
printf("\n")
}
Then invoke awk thusly:
awk -F, -f my.awk -v "lo=202" -v "hi=215" myinputfile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-03-2003 11:22 AM
тАО03-03-2003 11:22 AM
Re: Query on the file
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-03-2003 11:41 AM
тАО03-03-2003 11:41 AM
Re: Query on the file
Hi,
Or a shell script, call it "myscript" and do:
myscript
IFS=","
typeset -i cntr a
cntr=0
while read a b
do
if [[ $a -ge 202 && $a -le 215 ]]
then
cntr=$cntr+1
fi
done
echo $cntr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-03-2003 11:44 AM
тАО03-03-2003 11:44 AM
Re: Query on the file
I have a quick question in korn shell. I don't think korn shell supports integers of 18 digits. Is there a work around for this in korn shell itself.
Any help is greatly appreciated.
Yours sincerely,
Chandra
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-03-2003 11:53 AM
тАО03-03-2003 11:53 AM
Re: Query on the file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-03-2003 12:19 PM
тАО03-03-2003 12:19 PM
Re: Query on the file
I did not read your description carefully enough.
Here is an example shell script with start and end line numbers.
IFS=","
typeset -i cntr a start end line
cntr=0
start=0
end=0
line=0
while read a b
do
line=line+1
if [[ $a -ge 202 && $a -le 215 ]]
then
cntr=$cntr+1
if [ $start -eq 0 ]
then
start=$line
fi
end=$line
fi
done
echo Nr: $cntr Start: $start End: $end
No points for this .
Leif