open files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting open files
# 1  
Old 03-15-2011
open files

I want to open a file and edit it using vi However, i dont want to open directories or binary files. how can i do this?

Right now it opens all files without caring

Code:
echo "please enter a file to edit in Vi"
read file

if [  'grep " $file"'   ]

then

# 2  
Old 03-15-2011
do a check whether its a dir or regular file, before you open it:

Code:
if [ -d $file ] ; then echo "its a dir" ; fi
if [ -f $file ] ; then echo "its a regular file" ; fi

Also, you got single quotes there, which is probably not what you want. You want "backticks", which is the key next to '1'.
# 3  
Old 03-15-2011
You could start by making sure file is a regular file and is readable (or writable?). Then checking output of "file" command for "ASCII" might be enough:

Code:
if [ -f "$file" ] && [ -r "$file" ]
then
    file "$file" | grep -q "ASCII"
    if [ $? -eq 0]
    then
        vi "$file"
    else
       echo "$file" "is not an ASCII file - vi not allowed"
    fi
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Process to use open files

I would like to test open files usage in my system, if I want to create a process ( or script ) that can use a certain amount ( eg. 1000 ) of open files , is it possible to create such process ( or script ) ? (3 Replies)
Discussion started by: ust
3 Replies

2. Shell Programming and Scripting

Flagging Open Files

A quick breakdown of my situation: I have 2 servers running OS 10.7, one in the US, the other in China. A folder is being synchronized via EMC's "Syncplicity". Here is my problem- When we open an Excel spreadsheet on one server, Syncplicity does not sync over the temporary file that Excel... (0 Replies)
Discussion started by: sudo
0 Replies

3. Red Hat

How to open RAR files?

May be this is a newbie question but i want to know hoe to open the RAR file in linux? (1 Reply)
Discussion started by: ashok.g
1 Replies

4. UNIX for Dummies Questions & Answers

How can i open rar files

Is there a way to open rar files on linux i would really appretiate if u would help :) (2 Replies)
Discussion started by: abu_malek
2 Replies

5. Programming

Too many open files - C++ on Unix

Hi all, My requirement is like this: I have list of numbers, i need to get the data related to those numbers from database and write the information into a file . I am using open function to write data related to one number. Close the file. Get the next number ,write data and close again. ... (2 Replies)
Discussion started by: parvathi_rd
2 Replies

6. OS X (Apple)

Open Files for a process

I am having a client/server application which will download files from server. If server has directories, it will create directories/sub directories and then download files. In this process, I observed that number of open files are more than 400 (which is approxmately same as number of dir/subdir... (1 Reply)
Discussion started by: satyam90
1 Replies

7. UNIX for Advanced & Expert Users

Too Many files open

Hi , We are using a Tool which runs on Unix Server. Have a Event which have some join operation and tries to open files depending on the join operation. So get the error config/variants/orcl6/partitions/ml6/data/ap_PCardMap.csv (Too many open files) Can someone please... (3 Replies)
Discussion started by: shashank_recj
3 Replies

8. Solaris

How to check no. of files open currently

I'm getting an error "too many files open" # ulimit -a time(seconds) unlimited file(blocks) unlimited data(kbytes) unlimited stack(kbytes) 8192 coredump(blocks) unlimited nofiles(descriptors) 256 memory(kbytes) unlimited # hard limit shows 1024 I would like to know how many files... (1 Reply)
Discussion started by: max_min
1 Replies

9. UNIX for Advanced & Expert Users

too many files open and questions

Hi all, Presently I'm using a 3pp that uses fopen to open files and I encounter this problem of too many files open when it is trying to open a file. My application is done in java which interfaces with this 3pp. When I instantiate this 3pp it loads up some files but it is pops up the error... (7 Replies)
Discussion started by: lmcanth
7 Replies

10. 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
Login or Register to Ask a Question