In principle: yes, but as you want to implement the "-r" option you need to break down this class to its member characters anyway.
You might want to start with the following thought: how does a script receive input? There are two ways: via <stdin> and via a file it reads from. If you use:
The script is supposed to open that file and get its input by reading from it. If - in opposition to that - you use
or
The script gets its input by reading from <stdin>. You should start by researching and understanding how a script gathers input in these two ways prior to changing this input.
I hope this helps.
bakunin
I see. I was thinking of using an if else statement to check whether if there is an argument for the command or not. If there is an argument, then the command would use that argument, which is the file input. If there is none, then it is through standard input.
In perl I want to do remove the top line of my input file then process the next line. I want to do something like
head -1 inputfile > temp
grep -v temp inputfile > newinputfile
cp newinputfile inputfle
is this possible in perl? (3 Replies)
how can i redirect standard input? i dont remember :/, though could you redirec not from a command? i mean, to redirect always stdin and stout (1 Reply)
I tried copy the output files from find command into a directory.
Example,
find / -name core 2>/dev/null | xargs cp????
I have known that we can use xargs to execute command lines from standard input but how to use it in this case.
Or I can do something besides xargs. (2 Replies)
Hi,
How can I removed the directory in the input file?
The script responsible for storing the report in an input file is this:
while }" ]
do
echo "penetration|${penfilename}|${penfilenamedaterange}" >> ${OUT_DIR}/penrpt_emailfile.txt
(( i=i+1 ))
done
For the penfilename:
... (2 Replies)
Hi
I am trying to write a shell script which should take the file as standard input. As file(content and name both) will change for each run. It should read the file line by line. with each line I have to perform certain operation.
For example
I have i file foo, it looks like
/usr/doc/abc... (4 Replies)
Hello,
I am new to scripting.
How do I read multiple lines from the command line?
I know read reads one line, but if I have to read multiple lines, how should I do?
Thanks,
Prasanna (4 Replies)
So, I am new to shell scripting and have a few problems.
I know how to read from standard input but I do not know how to really compare it to say, a character. I am trying to compare it to a character and anything exceeding just a character, the user will get an output message, but the program... (7 Replies)
Hi Geeks,
I am relatively new to Unix. Trying out to achive a shell script by hard learning. Here is my requirment.
1. I have to search for specified strings that are given in .csv file in the directory to find the files for matching strings in the .csv file.
2. If match is found, copy... (1 Reply)
I want to use a content of a file as standard input to a program and dump the output to a file. However, when I try the following code:
./program < input.in > output.out
The output.out is empty. So, how can I handle this problem?
Thanks in advance! (11 Replies)
Discussion started by: Ray Sun
11 Replies
LEARN ABOUT XFREE86
edinplace
edinplace(1) Mail Avenger 0.8.3 edinplace(1)NAME
edinplace - edit a file in place
SYNOPSIS
edinplace [--error=code] [[--file=file] command [arg ...]]
DESCRIPTION
edinplace runs command with its input from file (or standard input by default), and then replaces the contents of file with the output of
command. To the extent possible, edinplace attempts to exit with the same status as command.
If edinplace is run on standard input (no --file option), it must inherit a file descriptor 0 that is open for both reading and writing.
When processing standard input, if edinplace does not encounter a fatal error, it rewinds its standard input to offset 0 before exiting.
Thus, a script can first run edinplace command, then run another filter command such as grep, and the resulting output will be the output
of grep on command's output.
If no command is specified, edinplace just rewinds its standard input to file offset 0. In this case, it is an error to supply the --file
option. Of course, rewinding only works when standard input is a real file (as opposed to a pipe or device).
There are two options:
--error=code (-x code)
Ordinarily, edinplace attempts to exit with the same status as command. However, if edinplace encounters some fatal error (such as
being unable to execute command), it will exit with status code. The default value is 1. The range of valid exit codes is 1-255,
inclusive.
--file=file (-f file)
Specifies that file should be edited. Otherwise, edinplace will edit its standard input (which must be opened for both reading and
writing).
--skipfrom
Skip the first line of the file if it starts "From ". If edinplace is run without a command, positions the file offset at the start of
the second line of the file. If edinplace is run with a command, then the first line of the file is neither fed to the command, nor
overwritten. This option is useful for running edinplace over mail files, which sometimes start with a "From " line specifying the
envelope sender of the message. Since "From " is not part of the message header, just a Unix convention, some programs are confused by
the presence of that line. Note that if you specify a command, then edinplace resets the file offset to 0 upon exiting, even if the
--skipfrom option was present.
EXAMPLES
The following command prepends the string "ORIGINAL: " to the beginning of each line in text file message:
edinplace -f message sed -e 's/^/ORIGINAL: /'
The following command runs the spamassassin mail filter program on a mail message stored in file message, replacing the contents of message
with spamassassin's annotated output, and exiting with code 100 if spamassassin thinks the message is spam. If edinplace encounters any
fatal errors, it will exit with code 111.
edinplace -x 111 -f message spamassassin -e 100
(spamassassin reads a mail message on standard input and outputs an annotated copy of the message including information about whether or
not the message is likely to be spam and why. The -e option to spamassassin specifies what exit status spamassassin should use if the
message appears to be spam; edinplace will use the same exit code as the program it has run.)
To run spamassassin on incoming mail before accepting the mail from the remote client, place the following line in an appropriate Mail
Avenger rcpt file as the last command executed:
bodytest edinplace -x 111 spamassassin -e 100
SEE ALSO avenger(1)
The Mail Avenger home page: <http://www.mailavenger.org/>.
BUGS
edinplace does not make a copy of the file being edited, but rather overwrites the file as it is being processed. At any point where
command has produced more output than it has consumed input from the file, edinplace buffers the difference in memory. Thus, a command
that outputs large amounts of data before reading the input file can run edinplace out of memory. (A program that outputs data as it reads
even a very large file should be fine, however.)
If command crashes or malfunctions for any reason, you will likely lose the input file, since edinplace will view this as a program that
simply outputs the empty file.
AUTHOR
David Mazieres
Mail Avenger 0.8.3 2012-04-05 edinplace(1)