I'm trying to understand xargs, though. What does that do for me here? I only ask b/c I've never used before.
It is possible to have written the command like this:
except that the result of the egrep might be more arguments than can be handled on a single command line. By piping the output to xargs, xargs will execute the command that you give it (cat in this case) with n number of arguments such that n does not exceed the limit from a command line perspective. It may invoke the command multiple times to accomplish its task.
With this said, I realise that my original command would be flawed as the '*' given to egrep might expand into too many arguments, causing an error, and thus the xargs in this case would do no good. This would probably be better:
The ls command generates a list of filenames which is given to egrep via the first xargs. The result of the searches is then given to cat via the second xargs.
When writing a script it is usually best to assume the worst case and use xargs in this situation. If you're willing to live with the errors, and are pretty sure that there will not be more files in a directory than the max allowable args on a command line, then the first form (without xargs) is easiest and straightforward.
Hi,
I need to get the latest file from a list of files in a particular directory.
Please could anyone help me out to get the file.
Thank you,
- Jay. (1 Reply)
I would like ot create shell script/ bash to create diffrent files based on a file and parameters list.
Here is the detail example: I have a textfile and four static parameter files (having ‘?'). mainfile.txt has below records (this count may be more than 50)
A200001
A200101
B200001... (9 Replies)
Good morning guys!!
Im still practicing with Perl and now Im trying to open a file, and copy its contents to another file. Them I want to remeove the information out of the orginal file after it is copied over.
The flow should be messages-->messages1-->messages2.
Kind of like a log... (1 Reply)
Hello,
I'm trying to move the log files from the parent directory to respective monthly folder and I would be running this script on a weekly basis through cron.
I'm new to this scripting and here is what i could come up and it runs without really doing anything. I even tried placing echo... (2 Replies)
hi
i want to scp files from remote server B to my local server A...
and i have a file containing list of all files to be scped from remote server B
there is a passwordless connectivity set between remote server and my local server.
need a ksh script.. with a for loop that goes through... (2 Replies)
Hi,
I'm quite new to ksh scripting, can someone help me with this.
Requirements:
I need to create a script that list the files from a user input date range.
e. g. format of file:
*c1*log.2012-12-22-14-00*
*c1*log.2012-12-22-14-00*
*c1*log.2012-12-22-14-00*... (7 Replies)
Hi,
I need help with this-
input.txt :
L B white
X Y white
A B brown
M Y black
Read this input file and if 3rd column is "white", then add specific lines to another file insert.txt.
If 3rd column is brown, add different set of lines to insert.txt, and so on.
For example, the given... (6 Replies)
Hi,
I have two pipe separated files as below:
head -3 file1.txt
"HD"|"Nov 11 2016 4:08AM"|"0000000018"
"DT"|"240350264"|"56432"
"DT"|"240350264"|"56432"
head -3 file2.txt
"HD"|"Nov 15 2016 2:18AM"|"0000000019"
"DT"|"240350264"|"56432"
"DT"|"240350264"|"56432"
I want to list the... (6 Replies)
Hi All,
In the file names we have dates.
Based on the file format given by the user,
if any file is not existed for a particular date with in a given interval we should consider that file is missing.
I have the below files in the directory /bin/daily/voda_files.
... (9 Replies)
Discussion started by: nalu
9 Replies
LEARN ABOUT REDHAT
xargs
XARGS(1L)XARGS(1L)NAME
xargs - build and execute command lines from standard input
SYNOPSIS
xargs [-0prtx] [-e[eof-str]] [-i[replace-str]] [-l[max-lines]] [-n max-args] [-s max-chars] [-P max-procs] [--null] [--eof[=eof-str]]
[--replace[=replace-str]] [--max-lines[=max-lines]] [--interactive] [--max-chars=max-chars] [--verbose] [--exit] [--max-procs=max-procs]
[--max-args=max-args] [--no-run-if-empty] [--version] [--help] [command [initial-arguments]]
DESCRIPTION
This manual page documents the GNU version of xargs. xargs reads arguments from the standard input, delimited by blanks (which can be pro-
tected with double or single quotes or a backslash) or newlines, and executes the command (default is /bin/echo) one or more times with any
initial-arguments followed by arguments read from standard input. Blank lines on the standard input are ignored.
xargs exits with the following status:
0 if it succeeds
123 if any invocation of the command exited with status 1-125
124 if the command exited with status 255
125 if the command is killed by a signal
126 if the command cannot be run
127 if the command is not found
1 if some other error occurred.
OPTIONS
--null, -0
Input filenames are terminated by a null character instead of by whitespace, and the quotes and backslash are not special (every
character is taken literally). Disables the end of file string, which is treated like any other argument. Useful when arguments
might contain white space, quote marks, or backslashes. The GNU find -print0 option produces input suitable for this mode.
--eof[=eof-str], -e[eof-str]
Set the end of file string to eof-str. If the end of file string occurs as a line of input, the rest of the input is ignored. If
eof-str is omitted, there is no end of file string. If this option is not given, the end of file string defaults to "_".
--help Print a summary of the options to xargs and exit.
--replace[=replace-str], -i[replace-str]
Replace occurences of replace-str in the initial arguments with names read from standard input. Also, unquoted blanks do not termi-
nate arguments. If replace-str is omitted, it defaults to "{}" (like for `find -exec'). Implies -x and -l 1.
--max-lines[=max-lines], -l[max-lines]
Use at most max-lines nonblank input lines per command line; max-lines defaults to 1 if omitted. Trailing blanks cause an input
line to be logically continued on the next input line. Implies -x.
--max-args=max-args, -n max-args
Use at most max-args arguments per command line. Fewer than max-args arguments will be used if the size (see the -s option) is
exceeded, unless the -x option is given, in which case xargs will exit.
--interactive, -p
Prompt the user about whether to run each command line and read a line from the terminal. Only run the command line if the response
starts with `y' or `Y'. Implies -t.
--no-run-if-empty, -r
If the standard input does not contain any nonblanks, do not run the command. Normally, the command is run once even if there is no
input.
--max-chars=max-chars, -s max-chars
Use at most max-chars characters per command line, including the command and initial arguments and the terminating nulls at the ends
of the argument strings. The default is as large as possible, up to 20k characters.
--verbose, -t
Print the command line on the standard error output before executing it.
--version
Print the version number of xargs and exit.
--exit, -x
Exit if the size (see the -s option) is exceeded.
--max-procs=max-procs, -P max-procs
Run up to max-procs processes at a time; the default is 1. If max-procs is 0, xargs will run as many processes as possible at a
time. Use the -n option with -P; otherwise chances are that only one exec will be done.
SEE ALSO find(1L), locate(1L), locatedb(5L), updatedb(1) Finding Files (on-line in Info, or printed)
XARGS(1L)