The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
exit status of command in a pipe line topcat8 UNIX for Dummies Questions & Answers 10 10-19-2007 01:39 AM
How can I use pipe command ? bintaleb UNIX for Dummies Questions & Answers 11 04-16-2007 12:16 PM
Pipe out ftp command to a file lweegp UNIX for Dummies Questions & Answers 2 10-10-2005 02:40 AM
pipe command zomboo UNIX for Dummies Questions & Answers 1 10-31-2004 02:04 PM
ret val of a command in a pipe which is NOT the last one latze Shell Programming and Scripting 5 11-01-2002 06:32 AM

Closed Thread
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-20-2002
Registered User
 

Join Date: Mar 2002
Location: Aix-en-provence (France)
Posts: 3
How to pipe command

Hi All,


I want to create a command that executes a text editor with the most recent file in the current current directory.

So a good start to achieve this is :

ls -lrt | cut -c55- | tail -1

which provides the name of the most recent file in a directory

The problem is to pipe the result of this command with the text editor command (suppose dtpad).

So my question is : does it exist a way to make something like

ls -lrt | cut -c55- | tail -1 | dtpad XXXX

where XXXX is a variable or a command to force the dtpad command to take as parameter the result of the pipe


Thanks by advance,
Nicolas.
France
Forum Sponsor
  #2 (permalink)  
Old 03-20-2002
Registered User
 

Join Date: Feb 2002
Location: Bradford, UK
Posts: 70
You don't say what version of unix your on but try

dtpad `ls -lrt|cut -c55-|tail -1`
  #3 (permalink)  
Old 03-20-2002
Registered User
 

Join Date: Sep 2001
Posts: 36
Use 'find' to obtain the most recent files.

Ex: 'find $YOUR_DIR -mtime -5' will provide files with last modified date of less than 5 days....

then use dtpad as suggested by kevin.
  #4 (permalink)  
Old 03-20-2002
Registered User
 

Join Date: Mar 2002
Location: Aix-en-provence (France)
Posts: 3
Thumbs up

Quote:
Originally posted by Kevin Pryke
You don't say what version of unix your on but try

dtpad `ls -lrt|cut -c55-|tail -1`

Cool that works...

The unix version I use is SunOS 5.5.1 (result of uname -sr)


Nicolas
  #5 (permalink)  
Old 03-20-2002
Kelam_Magnus's Avatar
Unix does a body good.
 

Join Date: Aug 2001
Location: DFW McKinney, TX,
Posts: 1,069
alternate way, use awk

here is an alternate way that doesn't depend on a certain length to cut from-to.

It may be easier for you, I know it is for me. Also, you can use this principle in scripting as well.


dtpad `ls -lrt | awk '{ print $NF }' | tail -1`


This captures the last field and also gets rid of and leading or trailing spaces as well.

BTW, the $NF will always pull the last field. This is especially good if you have a line with more than 9 delimited fields, because $0 will print the whole line with the "awk" command.

UNIX is so great, we can do the same things in some many different ways!

UNIX RULESSSSSS!!!!!!!!!


__________________
My brain is your brain
Google The UNIX and Linux Forums
Closed Thread

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:30 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0