05-13-2008
Splitting input files into multiple files through AWK command
Hi,
I needs to split *.txt files from single directory depends on the some mutltiple input values. i have wrote the code like below
for file in *.txt
do
grep -i -h "value1|value2" $file > $file;
done.
My requirment is more input values needs to be given in grep; let us say 50 values($value1,$value2.....$value50).
is there any good way of writing the code.
example
aaa 1111 ee3456
bbb 2222 bb7658
kkk 8888 nn1234
hhh 5555 bb4444
lll 9999 ee0987
Also is it possible to split the file starting from 11th position to 15th position;
becaz i want split the file by considering position from the files so that my input values will reduce. like in exapmle(there are repeted values ee bb nn bb ee etc) from the file.
is that can be achived through AWK command?
Thanks in advance.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
What is the syntax to use multiple input files in a SED command. i.e. substitute a word with a phrase in every file in a directory.
for every file in /usr/include that has the word "date" in the file
grep -l '\<date\>' /usr/include/*.h
find each occurrence of the word "time" in the file &... (3 Replies)
Discussion started by: sheoguey
3 Replies
2. Shell Programming and Scripting
Hi All,
I am new to shell scripting..My problem is i want to give multiple csv files as input to awk script and process the data into one file..
My input file is
File1 File2 File3
Product Location Period SalesPrice
A x 8/11/2010 ... (7 Replies)
Discussion started by: kvth
7 Replies
3. Shell Programming and Scripting
I have an input file with contents like:
MainFile.dat:
12247689|7896|77698080
16768900|hh78|78959390
12247689|7896|77698080
16768900|hh78|78959390
12247689|7896|77698080
16768900|hh78|78959390
12247689|7896|77698080
16768900|hh78|78959390
12247689|7896|77698080
16768900|hh78|78959390
... (4 Replies)
Discussion started by: rkrish
4 Replies
4. UNIX for Dummies Questions & Answers
Hello,
I am new to UNIX etc and am trying to split a large number of files, all with the extension .fas in the same folder, into smaller files wherever a string of 5ns occurs.
So this file:
>File1.fas
nnnnnaaaaaattgattttctcagtatcgacgaatatggcgcagaaagttgaataa ... (1 Reply)
Discussion started by: Bryony
1 Replies
5. Shell Programming and Scripting
Hello,
For the input file, I am trying to split those records which have multiple values seperated by '|' in the last input field, into multiple records and each record corresponds to the common input fields + one of the value from the last field.
I was trying with an example on this forum... (4 Replies)
Discussion started by: imtiaz99
4 Replies
6. Shell Programming and Scripting
Hi!
I'm new in awk and I need some help.
I have a folder with a lot of files and I need that awk do something in each file and print a new file with the output. The input file name should be modified when I print the outpu files.
Thanks in advance for help!
:-)
ciao (5 Replies)
Discussion started by: gabrysfe
5 Replies
7. Shell Programming and Scripting
Hi ,
I am receiving a CSV file that can vary in number of rows each time.
I am supposed to split this file into 3 separate files like this:
1. create a file named 'File1.csv' that will contain first 3 rows of the input file
2. create file named 'File2.csv' that will contain last 3 rows of the... (7 Replies)
Discussion started by: kedrick
7 Replies
8. Shell Programming and Scripting
Hi all ,
i want to pass multiple files as input to a for loop
for i in file1 file2 file3
do
some awk action < $i >> $i.out
done
but im getting error in that for loop is the way i use to pass files to awk using for correct and
2.we can directly pass multiple files to awk as... (7 Replies)
Discussion started by: zozoo
7 Replies
9. Shell Programming and Scripting
Hi,
I have many test*.ft1 files to which I want to read as input for a script called
pipe2txt.tcl and print the output in each separate file.
For example,
pipe2txt.tcl < test001.ft1 > test001.txt
How can I read many files in this maner?
thank you very much,
Best,
Pahuja (5 Replies)
Discussion started by: Pahuja
5 Replies
10. Open Source
I have a process that requires me to read data from huge log files and find the most recent entry on a per-user basis. The number of users may fluctuate wildly month to month, so I can't code for it with names or a set number of variables to capture the data, and the files are large so I don't... (7 Replies)
Discussion started by: rbatte1
7 Replies
LEARN ABOUT OPENDARWIN
split
SPLIT(1) BSD General Commands Manual SPLIT(1)
NAME
split -- split a file into pieces
SYNOPSIS
split [-a suffix_length] [-b byte_count[k|m]] [-l line_count] [-p pattern] [file [name]]
DESCRIPTION
The split utility reads the given file and breaks it up into files of 1000 lines each. If file is a single dash ('-') or absent, split reads
from the standard input.
The options are as follows:
-a Use suffix_length letters to form the suffix of the file name.
-b Create smaller files byte_count bytes in length. If ``k'' is appended to the number, the file is split into byte_count kilobyte
pieces. If ``m'' is appended to the number, the file is split into byte_count megabyte pieces.
-l Create smaller files n lines in length.
-p pattern
The file is split whenever an input line matches pattern, which is interpreted as an extended regular expression. The matching line
will be the first line of the next output file. This option is incompatible with the -b and -l options.
If additional arguments are specified, the first is used as the name of the input file which is to be split. If a second additional argument
is specified, it is used as a prefix for the names of the files into which the file is split. In this case, each file into which the file is
split is named by the prefix followed by a lexically ordered suffix using suffix_length characters in the range ``a-z''. If -a is not speci-
fied, two letters are used as the suffix.
If the name argument is not specified, the file is split into lexically ordered files named with prefixes in the range of ``x-z'' and with
suffixes as above.
SEE ALSO
csplit(1), re_format(7)
STANDARDS
The split utility conforms to IEEE Std 1003.1-2001 (``POSIX.1'').
HISTORY
A split command appeared in Version 3 AT&T UNIX.
BUGS
For historical reasons, if you specify name, split can only create 676 separate files. The default naming convention allows 2028 separate
files. The -a option can be used to work around this limitation.
The maximum line length for matching patterns is 65536.
BSD
April 16, 1994 BSD