Sponsored Content
Top Forums Shell Programming and Scripting Split file by number of words Post 302456235 by rdcwayx on Thursday 23rd of September 2010 05:08:20 PM
Old 09-23-2010
Code:
xargs -n1 <infile |head -200

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To read and separate number and words in file and store to two new file using shell

hi, I am a begginer in unix and i want to know how to open a file and read it and separate the numbers & words and storing it in separate files, Using shell scripting. Please help me out for this. Regards S.Kamakshi (2 Replies)
Discussion started by: kamakshi s
2 Replies

2. UNIX for Dummies Questions & Answers

split a file into a specified number of files

I have been googling on the 'split' unix command to see if it can split a large file into 'n' number of files. Can anyone spare an example or a code snippet? Thanks, - CB (2 Replies)
Discussion started by: ChicagoBlues
2 Replies

3. Shell Programming and Scripting

Split File of Number with spaces

How do i split a variable of numbers with spaces... for example echo "100 100 100 100" > temp.txt as the values can always change in temp.txt, i think it will be feasible to split the numbers in accordance to column. How is it possible to make it into $a $b $c $d? (3 Replies)
Discussion started by: dplate07
3 Replies

4. Shell Programming and Scripting

Finding the number of unique words in a file

find the number of unique words in a file using sort com- mand. (7 Replies)
Discussion started by: abhikamune
7 Replies

5. Shell Programming and Scripting

Counting number of files that contain words stored in another file

Hi All, I have written a script on this but it does not do the requisite job. My requirement is this: 1. I have two kinds of files each with different extensions. One set of files are *.dat (6000 unique DAT files all in one directory) and another set *.dic files (6000 unique DIC files in... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

6. Shell Programming and Scripting

Count the number of words in some subset of file and disregard others

Hi All, I have some 6000 text files in a directory. My files are named like 1.txt, 2.txt 3.txt and so on until 6000.txt. I want to count the "number of words" in only first 3000 of them. Any suggestions? I know wc -w can count the number of words in a text file. I am using Red Hat Linux. (3 Replies)
Discussion started by: shoaibjameel123
3 Replies

7. UNIX for Dummies Questions & Answers

Split single file into n number of files

Hi, I am new to unix. we have a requirement here to split a single file into multiples files based on the number of people available for processing. So i tried my hand at writing some code as below. #!/bin/bash var1=`wc -l $filename` var2=$var1/$splitno split -l $var2 $1 Please help me... (6 Replies)
Discussion started by: quirkguy
6 Replies

8. Shell Programming and Scripting

problem to count number of words from file

hi every one i have written this simple shell for counting number of word that user need to find from file but i have get several error when run it. can someone tell me the problem ? echo "Enter the file name" read file echo "enter word" read word for i in \`cat $file` do if then... (1 Reply)
Discussion started by: nimafire
1 Replies

9. Shell Programming and Scripting

How count the number of two words associated with the two words occurring in the file?

Hi , I need to count the number of errors associated with the two words occurring in the file. It's about counting the occurrences of the word "error" for where is the word "index.js". As such the command should look like. Please kindly help. I was trying: grep "error" log.txt | wc -l (1 Reply)
Discussion started by: jmarx
1 Replies

10. Shell Programming and Scripting

Split File based on number of rows

Hi I have a requirement, where i will receive multiple files in a folder (say: /fol1/fol2/). There will be at least 14 to 16 files. The size of the files will different, some may be 80GB or 90GB, some may be less than 5 GB (and the size of the files are very unpredictable). But the names of the... (10 Replies)
Discussion started by: kpk_ds
10 Replies
xargs(1)						      General Commands Manual							  xargs(1)

Name
       xargs - construct argument list and execute command

Syntax
       xargs [flags] [ command [initial-arguments] ]

Description
       The command combines fixed initial-arguments with arguments read from standard input to execute a specified command one or more times.  The
       number of arguments read when a command is invoked and how they are combined is determined by the options specified.

       The specified command, (which can be a Shell file) is searched for using ones' $PATH specification.  If command is not specified, /bin/echo
       is used.

       Arguments  read	from  standard	input  are defined as contiguous strings of characters delimited by one or more blanks, tabs, or newlines;
       empty lines are always discarded.  Blanks and tabs can be embedded as part of an argument if they contain an escape character  or  if  they
       are  quoted.   Characters enclosed in quotes (single or double) are taken literally, and the delimiting quotes are removed; a backslash ()
       escapes the next character.

Options
       Each argument list begins with the initial-arguments, followed by arguments read from standard input, with the exception of the -i  option.
       See the description of the -i option for more information.

       The  options -i, -l, and -n determine how arguments are selected when each command is invoked.  If none of these options are specified, the
       initial-arguments are followed by arguments read continuously from standard input until the internal buffer is full; then, command executes
       with  the accumulated arguments.  This process repeats until no arguments exist.  When conflicts arise, such as the -l option used with the
       -n, the last option has precedence. The options values are as follows:

       -lnumber
	     Execute command for each non-empty number lines of arguments from standard input.	When command is invoked for the final time, it has
	     fewer  lines  of  arguments if fewer than a specified number remain.  A line ends with the first newline unless the last character of
	     the line is a blank or a tab; a trailing blank or tab signals continuation through the next non-empty line.   If  number  is  is  not
	     specified, the value 1 is assumed.  The option -x is forced.

       -ireplstr (Insert mode)
	     Execute  command for each line from standard input, taking the entire line as a single argument and inserting it in initial-arguments
	     for each occurrence of replstr.  A maximum of five arguments specified in initial-arguments can contain one  or  more  occurrence	of
	     replstr.	Blanks and tabs at the beginning of each line are discarded.  A constructed arguments cannot exceed 255 characters and the
	     option -x is a forced.  A {|} is assumed for replstr if not specified.

       -nnumber
	     Execute command using as many standard input arguments as possible, up to the specified number arguments  maximum.   Fewer  arguments
	     are used if their total size is greater than size characters, and when the last command is invoked, fewer number of arguments remain.
	     If the option -x is also include, each specified number of arguments must fit in the size limitation, or else xargs terminates execu-
	     tion.

       -t (Trace mode)
	     Echo the command and each constructed argument list to file descriptor 2 prior to their execution.

       -p (Prompt mode)
	     Asks  the user whether or not command should be executed each time command is invoked. Trace mode (-t) is turned on to print the com-
	     mand instance to be executed, followed by a ?... prompt.  A reply of y executes the command; any other response does not invoke  that
	     particular command.

       -x    Causes  the  command xargs to terminate if an argument list is greater than the specified size of characters; the option -x is forced
	     by the options -i and -l.	When the options -i, -l, or -n are included, the total length of all arguments must be within  the  speci-
	     fied size limit.

       -ssize
	     The maximum size of each argument list is set to size characters; size must be a positive integer less than or equal to 470. If -s is
	     not included, 470 is the default.	Note that the character count for size includes one extra character  for  each	argument  and  the
	     count of characters in the command name.

       -eeofstr
	     The  option  eofstr  is  taken  as the logical end-of-file string.  Underscore (_) is assumed for the logical EOF string if -e is not
	     specified.  The value -e without eofstr specified turns off the logical EOF string capability; the  underscore  is  taken	literally.
	     The command xargs reads standard input until either end-of-file or the logical EOF string is encountered.

       The command xargs terminates if it receives a return code of -1 from command or if it cannot execute command.  When command is a Shell pro-
       gram, it should explicitly exit with an appropriate value to avoid returning with -1.  See for more information.

Examples
       The following example moves all files from directory $1 to directory $2 and echoes the move command prior to executing it:

       ls $1 | xargs -i -t mv $1/{} $2/{}

       The following example combines the output of the parenthesized commands onto one line, which is then echoed to the end of file log:

       (logname; date; echo $0 $*) | xargs >>log

       In the next example, the user is prompted to specify which files in the current directory are to be archived.  The first  example  archives
       the files one at a time; the second example archives groups of files:

	 ls | xargs -p -l ar r arch

	 ls | xargs -p -l | xargs ar r arch

       The following example executes diff(1) with successive pairs of arguments originally typed as Shell arguments:

       echo $* | xargs -n2 diff

See Also
       sh(1).

																	  xargs(1)
All times are GMT -4. The time now is 07:17 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy