From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <102653669622105.tru64-unix-managers.marc@archive.invalid> From: Jonathan Williams Date: Fri, 24 Aug 2001 15:38:05 +0000 To: tru64-unix-managers Subject: SUMMARY: Korn Shell Script Question X-MARC-Message: https://marc.info/?l=tru64-unix-managers&m=102653669622105 MIME-Version: 1 Content-Type: multipart/mixed; boundary="------=_NextPart_000_0311_01C12C91.3D4F6CE0" 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
Ok...thanks for all the fast = responses.  =20 Almost everyone suggested using "find" with the -ctime option.  = This would=20 be great, except as Tyler Hall pointed out:
>AFAIK, = the creation=20 date and the modification dates are the same value. Some programs = will read=20 in an entire file, >make the modifications, then write the = entire file=20 back out to disk, so in essence, the entire file would be new=20 >according to the OS. 
 
and it turns out this is exactly what = the program=20 does.  That's why the output of find . -mtime -1 and find . -ctime = -1 give=20 excatly the same output.  oh well...Thanks to all...

Jonathan Williams
UNIX Systems=20 Administrator
The Shubert Organization, = Inc.
------=_NextPart_000_0311_01C12C91.3D4F6CE0-- From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: "Brehl, Blake" Newsgroups: gmane.os.tru64.managers Subject: SUMMARY: korn shell script question Date: Thu, 23 Oct 2003 16:39:48 -0700 Sender: tru64-unix-managers-owner@ornl.gov Message-ID: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: sea.gmane.org 1066952413 2874 80.91.224.253 (23 Oct 2003 23:40:13 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 23 Oct 2003 23:40:13 +0000 (UTC) Original-X-From: tru64-unix-managers-owner-gotm-tru64-unix-managers=m.gmane.org@sws1.ctd.ornl.gov Fri Oct 24 01:40:11 2003 Return-path: Original-Received: from sws1.ornl.gov ([160.91.1.101]) by deer.gmane.org with smtp (Exim 3.35 #1 (Debian)) id 1ACp3q-0002kd-00 for ; Fri, 24 Oct 2003 01:40:10 +0200 Original-Received: (qmail 18774 invoked by uid 5); 23 Oct 2003 23:40:02 -0000 Original-Followup-To: poster Precedence: bulk Original-Received: (qmail 18759 invoked by uid 49493); 23 Oct 2003 23:40:02 -0000 Original-Received: from Blake.Brehl@anritsu.com by sws1 by uid 49491 with qmail-scanner-1.16 (iscan: v3.1/v5.600-1011/622/49252. clamscan: 20030605. spamassassin: 2.55. Clear:SA:0(-3.1/5.0):. Processed in 0.88732 secs); 23 Oct 2003 23:40:02 -0000 Original-Received: from unknown (HELO emroute2.cind.ornl.gov) (160.91.86.17) by 0 with SMTP; 23 Oct 2003 23:40:01 -0000 Original-Received: from emroute2.cind.ornl.gov (LOCALHOST [127.0.0.1]) by emroute2.cind.ornl.gov (PMDF V6.2-X17 #30669) with ESMTP id <0HN800DPFHQMYE@emroute2.cind.ornl.gov> for tru64-unix-managers@sws1.ctd.ornl.gov (ORCPT tru64-unix-managers@ornl.gov) ; Thu, 23 Oct 2003 19:40:01 -0400 (EDT) Original-Received: from mailhost2.us.anritsu.com (mailhost2.us.anritsu.com [12.151.36.154]) by emroute2.cind.ornl.gov (PMDF V6.2-X17 #30669) with ESMTP id <0HN800DLSHQDL6@emroute2.cind.ornl.gov> for tru64-unix-managers@sws1.ctd.ornl.gov (ORCPT tru64-unix-managers@ornl.gov) ; Thu, 23 Oct 2003 19:39:50 -0400 (EDT) Original-Received: from moh-exc-001.main.intgin.net ([172.26.1.92]) by mailhost2.us.anritsu.com with Microsoft SMTPSVC(5.0.2195.5329); Thu, 23 Oct 2003 16:39:49 -0700 Original-Received: by moh-exc-001.main.intgin.net with Internet Mail Service (5.5.2653.19) id ; Thu, 23 Oct 2003 16:39:49 -0700 Content-return: allowed Original-To: 'Tru64 Mailing List' X-Mailer: Internet Mail Service (5.5.2653.19) X-OriginalArrivalTime: 23 Oct 2003 23:39:49.0663 (UTC) FILETIME=[F3067AF0:01C399BE] Xref: main.gmane.org gmane.os.tru64.managers:5643 X-Report-Spam: http://spam.gmane.org/gmane.os.tru64.managers:5643 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