Print The ouput From ls | grep "!!!" | Unix Linux Forums | UNIX for Advanced & Expert Users

  Go Back    


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.

Print The ouput From ls | grep "!!!"

UNIX for Advanced & Expert Users


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 04-10-2002
geoquest geoquest is offline
Registered User
 
Join Date: Apr 2002
Last Activity: 19 June 2004, 11:31 AM EDT
Location: oman
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Print The ouput From ls | grep "!!!"

guys forget the find command coz with find command u can't get condational output like grep. I will give small example :-


Apr 10 09:12 aacbl222_12aug1998.lqc
Apr 10 09:12 sscbl4534_4sep2001.lqc
Apr 10 09:12 ah66fmi_5jan1997.lqc
Apr 10 09:12 y313h1_7sep1998.lqc
May 11 09:12 aalike_9aug2000.lqc

all this files and thosands more in /test/test2
to get my file I should give some parameter " in this example I give 2 gre some time it will take more than 6 grep's to get what I want " forget it "
--------------------------------------------------

ls -lrt | grep "Apr 10" | grep 1998

Apr 10 09:12 y313h1_7sep1998.lqc
Apr 10 09:12 aacbl222_12aug1998.lqc

--------------------------------------------------

now when I want to print what I got from my command I will do this : -

print y313h1_7sep1998.lqc ; print aacbl222_12aug1998.lqc

when I type

ls -lrt | grep "Apr 10" | grep 1998 | lp
I will get the printe of result not the file it self...Pleassse try to understand me and execuse me for my "GOOD" english

Better to read all what I wrote above or just read this

[ HOW I CAN PRINT THE RESULTED FILES AS A FILE NOT AS OUTPUT ]
Sponsored Links
    #2  
Old 04-10-2002
inpavan inpavan is offline
Registered User
 
Join Date: Sep 2001
Last Activity: 18 December 2002, 6:21 AM EST
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Havent I already answered the question?..

Or Was the command unsuccessful?
Sponsored Links
    #3  
Old 04-10-2002
isacs isacs is offline
Registered User
 
Join Date: Mar 2002
Last Activity: 9 March 2006, 5:49 AM EST
Location: Muenster - Germany
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
The answer is...

pipe the output in a file

ls > FILE.txt

creates or if exists overwrites the file FILE.txt and stores the output of the ls command in it.

ls >> FILE.txt appends the output of the command if the file exists or create a new one if not


hope this solves your problem




see the other thread as well

Frank
    #4  
Old 04-10-2002
geoquest geoquest is offline
Registered User
 
Join Date: Apr 2002
Last Activity: 19 June 2004, 11:31 AM EDT
Location: oman
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
COME ON GUYS

Please try to understand me

ls | grep "bla bla bla" >> result.txt

ok I will get the result in result.txt as u said then I want to print the files, don't tell me to print result.txt coz I will get in name of the file in the print out and I want to print the information inside the file.It's very simple please don't make me feel my english toooo BAD & unix As well

what I want is the fastest way to print multipul files

what I'm using right now is

print file1 ; print file2 ; print file3 ; print file4
Sponsored Links
    #5  
Old 04-10-2002
LivinFree's Avatar
LivinFree LivinFree is offline Forum Advisor  
Goober Extraordinaire
 
Join Date: Jul 2001
Last Activity: 16 June 2011, 4:50 PM EDT
Location: Portland, OR, USA
Posts: 1,626
Thanks: 2
Thanked 15 Times in 13 Posts
Please please read this carefully and try it out before deciding it won't work, because as far as I can tell, it will!

I think that if you can figure out exactly what you are needing to do (which files to print, and when), you could use a very simple find command to do it.
But if you really really really want to use grep a bunch of times, you could do this:

Code:
ls -ltr | grep "Apr 10*1998.lqc" > /tmp/lp_file
print `cat /tmp/lp_file`

or use:

Code:
for each in `cat /tmp/lp_file`; do print $each; done

Note: I used backticks ` not single quotes ' above. The backticks are usually near the top left on a standard PC keyboard.

Or like this (if you can narrow what you want down by the filename):

Code:
for each in *sep2001.lcq; do; print $each; done

Or what about :

Code:
ls -lrt | grep "Apr 10*1998.lqc" | xargs print

Some of these may complain of an error with too many arguments, or possibly that the jobs may not all print, so you may have to use the first/second idea of:

Code:
ls -lrt | grep "Apr 10*1998.lcq" > /tmp/lp_list
for each in `cat /tmp/lp_list; do print $each; done

These examples all assume you are using a Bourne shell variant, such as ksh, sh, bash, etc...

Please try these before posting back saying that none of them work. And please let us know why they don't work.
Sponsored Links
    #6  
Old 04-11-2002
Kelam_Magnus's Avatar
Kelam_Magnus Kelam_Magnus is offline Forum Advisor  
Registered User
 
Join Date: Aug 2001
Last Activity: 18 April 2013, 3:03 PM EDT
Location: San Antonio, TX,
Posts: 1,070
Thanks: 0
Thanked 4 Times in 4 Posts
Or even the basic step of taking the file.txt and adding print in the beginning of each line in the file and making it exe.

I know this is horrible scripting, but it works.

I agree that one of Livinfree's suggestions will work. see below his code.

code:
--------------------------------------------------------------------------------
for each in `cat /tmp/lp_file`; do print $each; done
--------------------------------------------------------------------------------
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
ps -ef | grep "string1" "string2" " "string3" steve2216 Shell Programming and Scripting 11 09-03-2010 11:08 AM
How to check "faulty" or "stalled" print queues - SAP systems? newbie_01 Solaris 0 07-15-2010 09:40 AM
MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else hariza Shell Programming and Scripting 4 09-18-2008 02:56 AM
Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" Lokesha UNIX for Dummies Questions & Answers 4 12-20-2007 12:52 AM
grep to find content in between curly braces, "{" and "}," keshav_rk Shell Programming and Scripting 4 08-09-2007 10:14 PM



All times are GMT -4. The time now is 06:08 AM.