tru64-unix-managers (formerly alpha-osf-managers) (1994-2012)
 help / color / mirror / Atom feed
* SUMMARY: Korn Shell Script Question
@ 2001-08-24 15:38 Jonathan Williams
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Williams @ 2001-08-24 15:38 UTC (permalink / raw)
  To: tru64-unix-managers

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: multipart/mixed; boundary="------=_NextPart_000_0311_01C12C91.3D4F6CE0", Size: 2381 bytes --]

This is a multi-part message in MIME format.

------=_NextPart_000_0311_01C12C91.3D4F6CE0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Ok...thanks for all the fast responses.   Almost everyone suggested =
using "find" with the -ctime option.  This would be great, except as =
Tyler Hall pointed out:
>AFAIK, the creation date and the modification dates are the same value. =
Some programs will read in an entire file, >make the modifications, then =
write the entire file back out to disk, so in essence, the entire file =
would be new >according to the OS.=20

and it turns out this is exactly what the program does.  That's why the =
output of find . -mtime -1 and find . -ctime -1 give excatly the same =
output.  oh well...Thanks to all...

Jonathan Williams
UNIX Systems Administrator
The Shubert Organization, Inc.

------=_NextPart_000_0311_01C12C91.3D4F6CE0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.3207.2500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Ok...thanks for all the fast =
responses.&nbsp;&nbsp;=20
Almost everyone suggested using "find" with the -ctime option.&nbsp; =
This would=20
be great, except as Tyler Hall pointed out:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2><FONT face=3DArial size=3D2>&gt;AFAIK, =
the creation=20
date and the modification dates are the same value.&nbsp;Some programs =
will read=20
in&nbsp;an entire file, &gt;make the modifications, then write the =
entire file=20
back out to&nbsp;disk, so in essence,&nbsp;the entire file would be new=20
&gt;according to the OS.&nbsp;</FONT></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>and it turns out this is exactly what =
the program=20
does.&nbsp; That's why the output of find . -mtime -1 and find . -ctime =
-1 give=20
excatly the same output.&nbsp; oh well...Thanks to all...</FONT></DIV>
<DIV><FONT face=3DArial size=3D2><BR>Jonathan Williams<BR>UNIX Systems=20
Administrator<BR>The Shubert Organization, =
Inc.</FONT></DIV></BODY></HTML>

------=_NextPart_000_0311_01C12C91.3D4F6CE0--

^ permalink raw reply	[flat|nested] 2+ messages in thread

* SUMMARY: korn shell script question
@ 2003-10-23 23:39 Brehl, Blake
  0 siblings, 0 replies; 2+ messages in thread
From: Brehl, Blake @ 2003-10-23 23:39 UTC (permalink / raw)


Hi,

Thank you for the many replies received, I ended up inserting a "| tail -1"
before the awk to do the trick. I didn't reflect the output correctly in the
original post, as 3 5 7.  It should have been:
3
5
7

Here's the reply's:

grep -in "End of Report" somefile | tail -1 | awk -F: '{print $1}'
grep -in "stuff" somefile | awk -F: '{print $1}' | tail -1
grep -in "End of Report" somefile | awk '{s=$1};END{print s}'
grep -in "End of Report" somefile | awk -F: '{print $1}' | tail -n 1
grep -in "End of Report" somefile | awk -F: '{last = $1} END {print last}'
#to avoid spawning more processes in the pipe
grep -in "End of Report" somefile | awk -F: '{print $1}'|tail -1
grep -in "End of Report" somefile | cut -f1 -d: | tail -n1

And an interesting one from Phil Farrell:

This is not really a Korn shell question, but rather, what UNIX utility to
use for your purpose.  How about doing the whole thing in awk, for example:

	awk '/End of Report/ {found=NR};END{print found}' somefile

Each time it finds the line with the regular expression within slashes, this
little program updates its "found" variable with the line number.  Then,
after looking at all input lines, in the END statement it prints the value
of the "found" variable, which will be the line number of the last line
found with that expression.

Many thanks to Iain, Jay, Mandell, Kris, James, Charles, Marcelo, Phil and
Dr. Thomas.

Best Regards,	Blake 

Thank you 

-----Original Message-----
I want to identify the number of the line of the last occurance of the
string "End of Report" within a file.

#> more somefile
line1
line2
End of Report
line4
End of Report
line6
End of Report
#>

#> #!/bin/ksh
#> grep -in "End of Report" somefile | awk -F: '{print $1}' 

results in

3 5 7

Is there a way to capture the last value (7), when you don't know how many
occurance?  I have gnugrep loaded if that is a better command.
  
TRU64UNIX V5.1A sp4

Best Regards,

Blake Brehl
Sys Admin/DBA
Anritsu Company United States
Morgan Hill, CA


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-10-23 23:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-08-24 15:38 SUMMARY: Korn Shell Script Question Jonathan Williams
  -- strict thread matches above, loose matches on Subject: below --
2003-10-23 23:39 SUMMARY: korn shell script question Brehl, Blake

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox