The only language that I ever have encountered with a built-in test for this was perl. I dislike perl and seldom use it. But I did give this feature a try. It seemed broken because it allowed many non-ascii characters before it finally declared a file to be binary. Since I then had to code my own test, I returned to ksh. But I do prefer perl's terminology. It calls this "text files" and "binary files".
Unless you inspect every byte of the file, you are not going to get this 100%. And there is a big performance hit with inspecting every byte. But after some experiments, I settled on an algorithm that works for me. I examine the first line and declare the file to be binary if I encounter even one non-text byte. It seems a little slack, I know, but I seem to get away with it.
Here is a little script that demonstrates this. Note that where I have used (TAB) to indicate a place where you must actually type the tab character.
Code:
#! /usr/bin/ksh
typeset -L30 fmtfile
for file in * ; do
if read line < $file ; then
if [[ "$line" = *[!\(TAB)\ -\~]* ]] ; then
type=binary
else
type=text
fi
else
type=unreadable
fi 2> /dev/null
fmtfile=$file
echo "$fmtfile is a $type file"
done
exit 0
I need to know what the best way, if possible in a perl or shell script, to determine if a file is open by a process, and if it is open for writing.
While I would rather use a perl or shell script, if I have to use C, that would be ok.
Thanks. (2 Replies)
Hello,
Can someone please tell me which command to use to determine the size of a file? When I log in to my shell account, I do this
$>% ls -als
total 632
8 -rw-r--r-- 1 user01 devgrp1 1558 Jul 30 23:25 .kshrc
What is "1158"? Bytes? Kilobytes?
I apologize if my... (8 Replies)
Hello,
How to i determine via ftp commandline if files on ftp server is ascii or binary files. Like every other comon windows ftp program does it automatically.
regards
Thomas (5 Replies)
Hello,
I am on a mission to determine the user of file. I have used the ls -l command but it displays permission, link, user, group, etc, but I just want to display just the name of user of a specified file.
Many thanks (4 Replies)
I have a file repository in a directory where files are copied into it by ftp or samba. Some of the ftp transfers can be slow, and some of the files can be fairly large. The files are not being used for anything in this directory other than being taken out of the directory and used by the... (2 Replies)
Hi gurus,
I have a file in unix with ascii values. I need to convert all the ascii values in the file to ascii characters. File contains nearly 20000 records with ascii values. (10 Replies)
A regular ebcdic mainframe tape usually contains header information the 1st three blocks of the tape. The header information tells the computer/user more information about what is on tape. The header info is 240 bytes in length at 80 bytes each header. The 1st block/header is volume name or... (1 Reply)
Hi All,
I'm just wondering how can i determined if there's a file in directory and put it in a logs?
dir="/home/test/"
Please advise,
Thanks,
Use code tags, thanks. (1 Reply)
Hi Folks,
While transferring file from FTP software like Filezilla the files gets corrupted.
Is there any way I can check if the recently transferred file is in ASCII and not corrupted. I have tried using file -i filename command which does tell if the file character set is ASCII or binary... (6 Replies)
Hi All,
I have an ascii file in which few columns are having hex values which i need to convert into ascii. Kindly suggest me what command can be used in unix shell scripting?
Thanks in Advance (2 Replies)
Discussion started by: HemaV
2 Replies
LEARN ABOUT MINIX
ng_hole
NG_HOLE(4) BSD Kernel Interfaces Manual NG_HOLE(4)NAME
ng_hole -- netgraph discard node type
SYNOPSIS
#include <sys/types.h>
#include <netgraph/ng_hole.h>
DESCRIPTION
The hole node type silently discards all data and control messages it receives. This type is used for testing and debugging.
HOOKS
A ng_hole node accepts any request to connect, regardless of the hook name, as long as the name is unique.
CONTROL MESSAGES
This node type supports the generic control messages, plus the following:
NGM_HOLE_GET_STATS
This command takes an ASCII string argument, the hook name, and returns the statistics associated with the hook as a struct
ng_hole_hookstat.
NGM_HOLE_CLR_STATS
This command takes an ASCII string argument, the hook name, and clears the statistics associated with the hook.
NGM_HOLE_GETCLR_STATS
This command is identical to NGM_HOLE_GET_STATS, except that the statistics are also atomically cleared.
SHUTDOWN
This node shuts down upon receipt of a NGM_SHUTDOWN control message, or when all hooks have been disconnected.
SEE ALSO netgraph(4), ng_echo(4), ngctl(8)HISTORY
The ng_hole node type was implemented in FreeBSD 4.0.
AUTHORS
Julian Elischer <julian@FreeBSD.org>
BSD May 19, 2004 BSD