The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
tail command and timestamp Begins Shell Programming and Scripting 6 04-16-2008 02:17 AM
tail command.. amon Shell Programming and Scripting 2 06-02-2006 04:36 AM
tail command whatisthis Shell Programming and Scripting 3 03-31-2005 09:34 AM
PIPEs and Named PIPEs (FIFO) Buffer size Jus Filesystems, Disks and Memory 1 08-20-2004 10:14 AM
tail command in SUN & HP_unix clemeot UNIX for Dummies Questions & Answers 3 05-08-2002 11:31 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-15-2005
sdlayeeq sdlayeeq is offline
Registered User
  
 

Join Date: Feb 2005
Posts: 10
Angry help with !(tail -2) command.. using pipes

I am trying to using pipe (|) with ! (not) operator to list all the other files except the latest two and I am using the following command.

$ ls -ltr *.lst|!(tail -2)
ksh: 20050211180252.lst: cannot execute

but it is trying to execute the file returned by tail -2. I am able to do that in 4 steps

1) ls -ltr *.lst > listfile
2) numberoflines=`wc -l | cut -d" "`
3) ((numberoflines = numberoflines - 2))
4) head -$numberoflines > final_list.

Are there any Unix gurus who could help me write the above commands using pipe facility. I am using Korn shell.

thanks in advance
  #2 (permalink)  
Old 02-15-2005
thumsup9 thumsup9 is offline
Registered User
  
 

Join Date: Jan 2005
Posts: 97
Try this:


ls -ltr *.lst|tail -r|tail +3|tail -r
  #3 (permalink)  
Old 02-15-2005
bhargav's Avatar
bhargav bhargav is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2004
Location: USA
Posts: 511
i do like this ...

Code:
ls -lt | awk '{ if (NR >3) print $0 }'
  #4 (permalink)  
Old 02-15-2005
sdlayeeq sdlayeeq is offline
Registered User
  
 

Join Date: Feb 2005
Posts: 10
Angry Thanks guys.. but still I am not getting the correct result

this is the actual pseudocode for the script I am developing

log files are created by timestamp, so need to extract unique time stamps and save in a list file.. EXCEPT the latest two, then I need to archive those files in an Archive folder (moving). so that only the latest two remains in the .LOG folder.

so I am doing. (awk '{print substr($9,1,14)} as filename is of 14 char.)

cd $LOGDIR
ls -ltr *.log |awk '{print substr($9,1,14)}'|sort -u|!(tail -2) > filenameslist

I tried the following command suggested by one of the guru.. but it is throwing me an error.

ls -ltr *.log |awk 'print substr($9,1,14)}'|sort -u|awk '{if (NR >3) print $0}' > filenameslist

Thanks a lot guys for the valuable thougts.. can any body have a better Idea.

challenge is to get it done using pipe.. I mean in one line
  #5 (permalink)  
Old 02-15-2005
sdlayeeq sdlayeeq is offline
Registered User
  
 

Join Date: Feb 2005
Posts: 10
Thumbs up Thank you all.. but is there any better way. avoid Awk for the second time

Thanks to all the guru's. but I thought is there a way to use
!(tail -2)..

can I avoid Awk for the second time Bhargav.. thanks in advance..
  #6 (permalink)  
Old 02-17-2005
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
why use awk? just use ls -lt|tail +4 and you are there.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:47 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0