Finding and using (only) ASCII files.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Finding and using (only) ASCII files.
# 1  
Old 06-07-2009
Question Finding and using (only) ASCII files.

Hi,

I had to do something I could do in a way that worked fine, but I'm still wondering if there's a shorter way (which I think there is)...

I had to find only the ASCII files of a directory, and then work with them (that is, not only showing on screen)

What I did was

Code:
 
ls | xargs file | grep "ASCII" | cut -d ":" -f 1 | xargs something......

That worked pretty well, but I think it's kinda long for such an supposed-to-be-easy task.

So, could you help me finding another way to find only the ASCII files of a directory? If possible, not using sed or awk, since I still don't know these commands at all.

Thanks a lot in advance,

Casey.
# 2  
Old 06-07-2009
Without using power tools like awk/sed/perl it's not possible to shorten your command so your best option is to stick with what you have.
# 3  
Old 06-07-2009
Only think I can think of here to reduce the number of pipelines is to remove the grep and cut and replace with awk.

Code:
ls | xargs file | awk -F: '/ASCII/{print $1}' | xargs something ...

Also an observation. This implementation ( | xargs something) is not "filename with a space" safe. You should use
Code:
xargs -I{} command {}

# 4  
Old 06-07-2009
Huh, I see... Looks like I'll keep using this command until I learn awk/sed.

Also, nice observation reborg.

Thanks to you both for your replies!! Smilie


Casey
# 5  
Old 06-07-2009
how about this
Code:
file * | awk -F":" '/ASCII/{print $1}'

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Convert files from binary to ASCII

I have a huge files in binary format thanks to help me in finding a way to convert these files from Binary format to ASCII format. (0 Replies)
Discussion started by: PRINCESS_RORO
0 Replies

2. UNIX for Advanced & Expert Users

line endings help of non-ASCII files

When you are dealing with ASCII files it easy to check on line endings type. You can just use the file command. You are not always lucky enough to be dealing with ASCII files. So in the cases that you don't have ASCII files how can you check what type of line endings you have? Please list all... (5 Replies)
Discussion started by: cokedude
5 Replies

3. UNIX for Dummies Questions & Answers

From Ascii files to Excell

Hi, Is there anyway to copy a certain column from the Ascii file into a column on an Excel sheet? Thanks, (4 Replies)
Discussion started by: cosmologist
4 Replies

4. Shell Programming and Scripting

finding duplicate files by size and finding pattern matching and its count

Hi, I have a challenging task,in which i have to find the duplicate files by its name and size,then i need to take anyone of the file.Then i need to open the file and find for more than one pattern and count of that pattern. Note:These are the samples of two files,but i can have more... (2 Replies)
Discussion started by: jerome Sukumar
2 Replies

5. UNIX for Advanced & Expert Users

Need to convert Binary files to ascii

Dear Experts I need to read a binary file. I know for example in byte number 3801-3804 there is a 4 byte number embeded. Is there a way to extract this number from this file and then convert it to ascii via unix?? Your help would be highly appreciated. Very Best Regards Reza (5 Replies)
Discussion started by: Reza Nazarian
5 Replies

6. UNIX for Dummies Questions & Answers

word count ascii files

how do I display the total number of words in a file which is of the type ascii text (1 Reply)
Discussion started by: madtim
1 Replies

7. UNIX for Dummies Questions & Answers

String substitutions in ASCII files -

We need to scramble data in a number of ASCII files. Some of these files are extremely large (1.2 GB). By scrambling, I mean that we need to substitute certain strings, which number around 400, with scrambled strings. An example has been given below If "London" occurs in the file, then it... (2 Replies)
Discussion started by: SanjivNagraj
2 Replies

8. Programming

open ASCII files

Anyone knows how to open an ASCII file by using C Thanks :D (2 Replies)
Discussion started by: Wing m. Cheng
2 Replies

9. UNIX for Dummies Questions & Answers

ASCII Files

Can you pls help on writing ASCII files? For example, how to you put SUPPLIER NO and NAME in an ASCIIfile? (1 Reply)
Discussion started by: yialousa
1 Replies

10. UNIX for Dummies Questions & Answers

How can I ... (Modifying large ASCII files)

Hi Everybody! Situation: I have a large ASCII file (for example: 1-2 Mbytes) without linebreaks (\n). Task: I like inserting linebreaks after all 420 digits (byte). (pattern: *\n*\n*\n...etc.) My problem: How? :-) I like using shell script or (maybe) AWK (short) program. Please,... (2 Replies)
Discussion started by: hviktor
2 Replies
Login or Register to Ask a Question