how to change this looking for mimetype "text/plain" instead of extension *.txt?

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions how to change this looking for mimetype "text/plain" instead of extension *.txt?
# 1  
Old 04-16-2011
how to change this looking for mimetype "text/plain" instead of extension *.txt?

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:

Create a Shell script that looks for all text files in your home directory (including subdirectories).
List only text files that all members of your group are able to "read and write".
These files shall be listed in the order "date of last change on file".
The permissions on and the full path of each file shall be listed, too.


2. Relevant commands, code, scripts, algorithms:


3. The attempts at a solution (include all code and scripts):
This is my solution (until now):
Here I'm looking for the file's extension "*.txt" but actually I've to look for the mime-type or so. Therefor the "file command" exists but I've no idea to adopt the mime-type into my script instead of the extension's search?


Code:
#! /bin/bash
 
 
 
 find ~ -name "*.txt" -printf "%M %f %TY%Tm%Td%TH%TM%TS %TY %Tm %Td %TH %TM %p\n" | sort -nk3 |
 awk '/^....rw/{
 
 filecnt = filecnt + 1
 printf ("No. %s", filecnt);
 printf ("  ***  filename: %s", $2 )
 printf ("  ***  filerights: %s", $1);
 printf ("  ***  last change on: %s.%s.%s um %s:%s h\n",$6, $5, $4, $7, $8)
 printf ("  ***  file path: %s\n", $9); 
 
 printf ("\n");
}'

4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
HAW Hamburg, Hamburg (Hamburg), Germany, Schneider, BS,http://ds2.etech.haw-hamburg.de/snd/veranst.html

Last edited by pludi; 04-16-2011 at 08:07 AM..
# 2  
Old 04-20-2011
Many files have text internally, and I am not sure there is a magic for plain text, so file might not be that useful. I actually wrote a pctbin C command to find out what percentage of characters were not in the common ASCII text file set: ' ' through '~', line feed, carriage return, form feed. The trick is figuring out what your professor defines as text!

You can find * -type f | xargs -n999 file and see all the types you have, and write a grep -E pattern that will select or deselect so only text types survive. You can use sed to remove the suffix of ": file type".

The permission are visible in find -ls or ls -l, and you can grep for them, too. Sorting by date is easy with ls -t, but ls has a file count limit. If you use the date, watch out for ls -l having a date-time form for one year and then a date-year form. I wrote a trivial C to take a stream of file name lines and spit them back out prefixed with the mtime.

Hope this helps!
# 3  
Old 04-20-2011
you can use file command's -i option. or --mime-type
# 4  
Old 04-21-2011
What Operating System and version are you running? It really matters for this type of question because there are extensions to standard unix commands available in some versions of Linux which could help.
Code:
uname -a

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

[Python] replicating "sha256 -C checksum_file.txt file.txt"

Hello everyone, Since my python knowledge is limimted, I've challenged myself to learn as much as possible to help me with my carrere. I'm currently trying to convert a shell script to python, just to give myself a task. There is one section of the script that I'm having issues converting and... (2 Replies)
Discussion started by: da1
2 Replies

2. Shell Programming and Scripting

Find lines with "A" then change "E" to "X" same line

I have a bunch of random character lines like ABCEDFG. I want to find all lines with "A" and then change any "E" to "X" in the same line. ALL lines with "A" will have an "X" somewhere in it. I have tried sed awk and vi editor. I get close, not quite there. I know someone has already solved this... (10 Replies)
Discussion started by: nightwatchrenba
10 Replies

3. Shell Programming and Scripting

Awk,sed : change every 2nd field ":" to "|"

Hi Experts, I have a string with colon delimited, want 2nd colon to be changed to a pipe. data: 101:8:43:4:72:14:41:69:85:3:137:4:3:0:4:0:9:3:0:3:12:3: I am trying with sed, but can change only 1 occurance: echo "101:8:43:4:72:14:41:69:85:3:137:4:3:0:4:0:9:3:0:3:12:3:" | sed 's/:/|/2'... (5 Replies)
Discussion started by: rveri
5 Replies

4. Shell Programming and Scripting

finding the strings beween 2 characters "/" & "/" in .txt file

Hi all. I have a .txt file that I need to sort it My file is like: 1- 88 chain0 MASTER (FF-TE) FFFF 1962510 /TCK T FD2TQHVTT1 /jtagc/jtag_instreg/updateinstr_reg_1 dff1 (TI,SO) 2- ... (10 Replies)
Discussion started by: Behrouzx77
10 Replies

5. Shell Programming and Scripting

Using sed to find text between a "string " and character ","

Hello everyone Sorry I have to add another sed question. I am searching a log file and need only the first 2 occurances of text which comes after (note the space) "string " and before a ",". I have tried sed -n 's/.*string \(*\),.*/\1/p' filewith some, but limited success. This gives out all... (10 Replies)
Discussion started by: haggismn
10 Replies

6. Shell Programming and Scripting

Help to change the file with "sed" and "awk"

Hi experts I want your help to change the file format to my wanted version, please give me a hand thanks $cat file install pass make os pass make build kernel failed usb storage pass chane to | *install* | *make os* | *make build kernel* | *usb storage* | | pass | pass... (7 Replies)
Discussion started by: yanglei_fage
7 Replies

7. Shell Programming and Scripting

delete " from plain text files

Hi, sorry for bothering with this easy problem but I can't understand... I've a file like this: "4","0x23a3" "5","0x4234" "11","" "20","" "11132","0x6456" I would like to create a file like this: 4,23a3 5,4234 11,999999 20,999999 11132,6456 I've tried: cat INPUT.txt | sed -e... (7 Replies)
Discussion started by: TheMrOrange
7 Replies

8. UNIX for Dummies Questions & Answers

Difference between plain "uniq" and "uniq -u"

Dear all, It's not entirely clear to me from manpage the difference between them. Why we still need "-u" flag? - monkfan (3 Replies)
Discussion started by: monkfan
3 Replies

9. UNIX for Dummies Questions & Answers

echo "ABC" > file1.txt file2.txt file3.txt

Hi Guru's, I need to create 3 files with the contents "ABC" using single command. Iam using: echo "ABC" > file1.txt file2.txt file3.txt the above command is not working. pls help me... With Regards / Ganapati (4 Replies)
Discussion started by: ganapati
4 Replies

10. Shell Programming and Scripting

Sorting problem "sort -k 16,29 sample.txt > output.txt"

Hi all, Iam trying to sort the contents of the file based on the position of the file. Example: $cat sample.txt 0101020060731 ## Header record 1c1 Berger Awc ANP20070201301 4000.50 1c2 Bose W G ANP20070201609 6000.70 1c2 Andy CK ANP20070201230 28000.00... (3 Replies)
Discussion started by: ganapati
3 Replies
Login or Register to Ask a Question