Determines a file is a NORMAL text file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Determines a file is a NORMAL text file
# 1  
Old 12-30-2011
Determines a file is a NORMAL text file

I assign the variable

Code:
name=`find . -type f | awk -vR=$num '{if (NR == R) {print; exit}}`

which returns the name of a file in "$num" ordered in the folder to the variable $name.
I want to use IF and determine if the file is a NORMAL text file (does not contain an extension), the command will display the file content, ELSE, exit the script.
What command can I use?
Thanks in advance.

---------- Post updated at 07:40 PM ---------- Previous update was at 07:33 PM ----------

i can even use the command:
Code:
name=`ls -1p | grep -v "/$" | awk -vR=$num '{if (NR == R) {print; exit}}`

so that the $name only contains the name of the file ( in find command, $name contains the path to the file) but ls command does not display files in subdirectories.
# 2  
Old 12-30-2011
Not sure what OS or shell you're using, but if you have the 'file' command available this may help point you in the right direction. If a file is some type of text file, the 'file' command should return it in it's description of the file:
i.e.
file testme
testme: Bourne-Again shell script text executable

Code:
[ $(file "$name" | grep -o -c 'text') == 1 ] && cat $name || echo "$name is not a text file"

Hope this helps.
This User Gave Thanks to in2nix4life For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Match text to lines in a file, iterate backwards until text or text substring matches, print to file

hi all, trying this using shell/bash with sed/awk/grep I have two files, one containing one column, the other containing multiple columns (comma delimited). file1.txt abc12345 def12345 ghi54321 ... file2.txt abc1,text1,texta abc,text2,textb def123,text3,textc gh,text4,textd... (6 Replies)
Discussion started by: shogun1970
6 Replies

2. Solaris

NFS - concurrent write to same file normal ?

Hi all, Sorry if I sound like a novice , I have always thought that for network file system which can be shared, there will be some access restriction in which when user A is writing/editing fileA, user B is able to view the same fileA but cannot write/edit it until user A has... (6 Replies)
Discussion started by: javanoob
6 Replies

3. Shell Programming and Scripting

Normal text to table format

Hi, I am trying to show my list, from a simple list format to a table (row and column formatted table) Currently i have this format in my output (the formart it will always be like this ) >> first 3 lines must be on the same line aligned, and the next 3 shud be on 2nd line....: INT1:... (10 Replies)
Discussion started by: eboye
10 Replies

4. UNIX for Dummies Questions & Answers

Extracting lines from a text file based on another text file with line numbers

Hi, I am trying to extract lines from a text file given a text file containing line numbers to be extracted from the first file. How do I go about doing this? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

5. Shell Programming and Scripting

csv file comparison with normal file

i will like to give my files as fileB : 02.09.2011:MOU04/KUBIS--R_Lieferung_1/KUBIS_V15.0/vpn_wls_15-0-0b01 02.09.2011:MOU04/KUBIS--R_Lieferung_2/KUBIS_V15.0/apng_wls_15-0-0b02 31 02.09.2011:MOU04/KUBIS--R_Lieferung_2/KUBIS_V15.0/ecc_wls_15-0-0b02 32 ... (2 Replies)
Discussion started by: rajniman
2 Replies

6. UNIX for Dummies Questions & Answers

[URGENT] Determines a file is a NORMAL text file

I assign the variable name=`find . -type f | awk -vR=$num '{if (NR == R) {print; exit}}` which returns the name of a file in "$num" ordered in the folder to the variable $name. I want to use IF and determine if the file is a NORMAL text file (does not contain an extension), the command will... (1 Reply)
Discussion started by: suyaku92
1 Replies

7. UNIX for Dummies Questions & Answers

Converting a text file with irregular spacing into a space delimited text file?

I have a text file with irregular spacing between values which makes it really difficult to manipulate. Is there an easy way to convert it into a space delimited text file so that all the spaces, double spaces, triple spaces, tabs between numbers are converted into spaces. The file looks like this:... (5 Replies)
Discussion started by: evelibertine
5 Replies

8. Shell Programming and Scripting

search text file in file if this file contains necessary text (awk,grep)

Hello friends! Help me pls to write correct awk and grep statements for my task: I have got files with name filename.txt It has such structure: Start of file FROM: address@domen.com (12...890) abc DATE: 11/23/2009 on Std SUBJECT: any subject End of file So, I must check, if this file... (4 Replies)
Discussion started by: candyme
4 Replies

9. Shell Programming and Scripting

how can I bcp out a table into a text file including the header row in the text file

Hi All, I need to BCP out a table into a text file along with the table headers. Normal BCP out command only bulk copies the data, and not the headers. I am using the following command: bcp database1..table1 out file1.dat -c -t\| -b1000 -A8192 -Uuser -Ppassword -efile.dat.err Regards,... (0 Replies)
Discussion started by: shilpa_acc
0 Replies

10. Linux

Deference between pipe and normal file

I want to know what is the architectural deference between a named pipe and normal file in unix . I know one is pipe only use direct blocks of inode.So what happens when it filled all direct blocks should it reset values after that. (0 Replies)
Discussion started by: mr_deb
0 Replies
Login or Register to Ask a Question