ls | grep (i dont know what to put here)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ls | grep (i dont know what to put here)
# 1  
Old 05-02-2011
ls | grep (i dont know what to put here)

Dear users,

I googled for a while, but i have got a lot of different answers regarding a simple unix command.

lets say there are a lot of files in a directory.

How can i list the files in a directory whose file types is "text"?

Thank you in advance
# 2  
Old 05-02-2011
You mean the filenames all end in .text?
Code:
ls *.text

actual text files can be any name in UNIX. the file type in the file name is not important like it is in windows.

Code:
ls | xargs file | grep 'text'

This finds files that are actually text of some sort.

Or just use
Code:
file * | grep 'text'

# 3  
Old 05-02-2011
Code:
ls | xargs file | grep 'text'
This finds files that are actually text of some sort.


This one is great..
Thanks a lot man. Really Thanks a lot.
# 4  
Old 05-02-2011
In solaris, there is a command file which can be used to identify if the file is text or binary file.
Code:
bash-3.00$ file 1
1:              commands text

bash-3.00$ file ftpmsg.log
ftpmsg.log:     commands text

bash-3.00$ file temp
temp:           directory

bash-3.00$ file port.tar
port.tar:  USTAR tar archive

So maybe this code can help you:
Code:
find . -type f -exec file {} \; |grep " text$"

# 5  
Old 05-03-2011
Thank you for your reply but I will use this one:

PHP Code:
ls xargs file grep 'text' 
looks like sweet and neat
as I only want to display the file of type text.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep the last line and put on mail subject

I have mail: cat /home/oracle/scripts/dbsizedaily.txt | mail -s "$TODAY: PROD DB Size" $RECIPIENTS I like to get and put USED_GB and %USED of the very last row from /home/oracle/scripts/dbsizedaily.txt. /home/oracle/scripts/dbsizedaily.txt has : DATE TIME TOTAL_GB USED_GB ... (6 Replies)
Discussion started by: Daniel Gate
6 Replies

2. Shell Programming and Scripting

Use grep sed or awk to extract string from log file and put into CSV

I'd like to copy strings from a log file and put them into a CSV. The strings could be on different line numbers, depending on size of log. Example Log File: File = foo.bat Date = 11/11/11 User = Foo Bar Size = 1024 ... CSV should look like: "foo.bat","11/11/11","Foo Bar","1024" (7 Replies)
Discussion started by: chipperuga
7 Replies

3. Shell Programming and Scripting

Perl XML, find matching condition and grep lines and put the lines somewhere else

Hi, my xml files looks something like this <Instance Name="New York"> <Description></Description> <Instance Name="A"> <Description></Description> <PropertyValue Key="false" Name="Building A" /> </Instance> <Instance Name="B"> ... (4 Replies)
Discussion started by: tententen
4 Replies

4. Shell Programming and Scripting

Extract columns from a file if the name dont exist put blank

Hi, I am very new to Unix script. Suppose i have a file with column header: NAME1 NAME2 Address Tel And I always need to make a file with column header: ID NAME1 NAME2 EMail Address Tel For the columns that do not exist in the file, I would still like to make a column with blank. ... (11 Replies)
Discussion started by: nightrider
11 Replies

5. UNIX for Advanced & Expert Users

ps avg | grep ? filter the desired out put.

Hi Folk, Following is the command I used to get data related to the DataFlowEngine. I wanted to know the % usage of cpu and memory. ps avg | grep Data This command will show the processes with its PID as : PID TTY STAT TIME PGIN SIZE RSS LIM TSIZ TRS %CPU %MEM COMMAND ... (1 Reply)
Discussion started by: varungupta
1 Replies

6. Shell Programming and Scripting

Grep strings from file and put in Column

Dear Experts, My file contains below- GET:SUB:ISI,432350414557432; RESP:0:MD,019352020633:ISI,432350414557432:T11,1:T21,1:T22,1:B16,1:T62,1:BAIC,0:BAOC,1:BOIC,0:BIRO,0:BORO,0:PAID,1; GET:SUB:ISI,432350414581060;... (2 Replies)
Discussion started by: thepurple
2 Replies

7. Shell Programming and Scripting

Grep command is not working when put into cron

Hi, I worte a script which runs perfect when i execute it manually. But when i scheduled into cron the grep command alone is not working. the sample script, /usr/bin/grep FTP $subfile > /tmp/tfsrec.dat tfs=`echo $?` if then echo "FTP FOUND" else echo "FTP NOT FOUND" Where... (5 Replies)
Discussion started by: thiru_cs
5 Replies

8. Shell Programming and Scripting

Put the output of grep in a variable

Hi, in a shell script how can I put the result of a grep command in a variable : myvariable=grep mystring myfilename Thank you. (3 Replies)
Discussion started by: big123456
3 Replies

9. Shell Programming and Scripting

how to put "grep" in the if condition..

i need a favour if ( grep -i adding mpg* | grep -iv equation | ls -ctr | tail -1 ) # if it is not found echo "log couldnot find " else var='grep -i adding mpg* | grep -iv equation | ls -ctr | tail -1' for the above i am struggling with syntax could someone please help me in that (1 Reply)
Discussion started by: mail2sant
1 Replies
Login or Register to Ask a Question