Creating two files out of one file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Creating two files out of one file
# 1  
Old 04-25-2013
Creating two files out of one file

Hi members,

I have a file with lots of text like this:
Code:
asdsfkm
dfsfom['
agko
dfblml;'
afdgpk
gkopdf
HUMAN 12 L 123E 43 
HUMAN 33 L 49235 123
HUMAN 43 L  J432 234
TER
HUMAN 9 D 3245 56
HUMAN 87 D 5856N 43
HUMAN 54 D 976 56
TER 
gsdfb
sdfg hyjf gh 
dgfj jk

now i want to extract only the rows with HUMAN as its 1st column
for this I used :
Code:
ruby -ne 'print if /^Human/; exit if /^TER/' $line | awk 'print $1, "\t"$2,  "\t"$3, "\t"$4, "\t"$5}' >$line"new"

This is creating a file containing data from first "HUMAN" to first TER. that is :
Code:
HUMAN 12 L 123E 43 
HUMAN 33 L 49235 123
HUMAN 43 L  J432 234

But, I need to create another file which should contain another data set after first "TER" till the second "TER", That is:
Code:
HUMAN 9 D 3245 56
HUMAN 87 D 5856N 43
HUMAN 54 D 976 56

which means that all "L" in 3rd row in one file and all "D" in 3rd row in second file. And also this L and D demarcation in filename.

Thanks in advance.
# 2  
Old 04-25-2013
Try something like this:
Code:
awk '/^HUMAN/{print > ( "set_" $3 )}' file

This User Gave Thanks to Scrutinizer For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Comparing two files and creating a new file

Hi, I want to compare two files based on the data in their first column. Both the files are not equal in their number of columns and number of entries or rows. The entries (only the first column) of the file1 should be compared with the entries (only the first column) of the file2. If the... (3 Replies)
Discussion started by: begin_shell
3 Replies

2. Shell Programming and Scripting

Creating a Third File from Information Contained in Two Files

In advance, I appreciate any help or tips. I apologize for not providing examples of scripts I have already tried, the reason is that I am new to programming and do not really no where to start. I think this is possible with awk, but do not know how to go about learning how to write the script... (2 Replies)
Discussion started by: awc228
2 Replies

3. UNIX for Dummies Questions & Answers

looping through file and creating seperate files

Hi, My first post!! I have a files with header, something like this Header_Row AMC|D1|D2|D2 AAO|D3|D4|D5 AMC|D6|D7|D8 AAO|D9|D10|D11 . . . . . and millions fo records thereafter like this. I want to read the above file in a loop and write the lines having AMC into another... (1 Reply)
Discussion started by: amitbakre
1 Replies

4. Shell Programming and Scripting

Creating a control file for a group of files

Hi, We have almost 45,000 data files created by a script daily. The file names are of format-ODS.POS.<pharmacyid>.<table name>.<timestamp>.dat. There will be one data file like this for each pharmacy and each table.(Totally around 45,000) The requirement is to create a control file for each... (2 Replies)
Discussion started by: Maya_Pillai
2 Replies

5. UNIX for Dummies Questions & Answers

Creating a Tar file while files are spooling

Hi I have done a search for this but couldn't find much on it. I am creating a tar file with the command below tar cvf /export/home/user/backup/*Will this is being created I have a job spooling to 5 texts files in the following directory /export/home/user/backup/STATS/ The tar files... (1 Reply)
Discussion started by: sgarvan
1 Replies

6. Shell Programming and Scripting

Creating a file with matching records from two other files

Hi All, I have 2 files (file1 & file2). File1 and File2 have m and n columns respectively I have to compare value in column1 of file1 with file2 and find line(s) from file2 matching column1 value. The value can be in any column in the matching lines of file2. The output should be... (10 Replies)
Discussion started by: Swagi
10 Replies

7. UNIX for Dummies Questions & Answers

Creating a file to count how many files in the directory

hello there i want to creat a file that count how many files i have in the directory. for this i use the command find . -type f | wc -l > 1In1.myfile the problem with this command is that it not update after i add a new file in the directory. Anyone got any ideas how i can... (5 Replies)
Discussion started by: AntiPin
5 Replies

8. Shell Programming and Scripting

ls > file - Creating file containing the list of all files present in a directory

Hi All, I need to create a file which contains the list of all the files present in that directory. e.g., ls /export/home/user/*.dat > list_file.dat but what i am getting is: $ ls /export/home/user/*.dat > list_file.dat /export/home/user/*.dat: No such file or directory But I have... (1 Reply)
Discussion started by: pranavagarwal
1 Replies

9. Shell Programming and Scripting

creating files and getting input from another file

I have a file where i have files name with absolute path. Ex: files.dat and contents are: /root/xy/yz/zz/abc.txt /root/xx/yy/zz/ac.txt /root/xz/yz/zx/bc.txt /root/xy/yz/zx/abcd.txt now i want to create all above files(dummy files and can be 0 byte). i thought of using touch but it doesn't... (10 Replies)
Discussion started by: ajayyadavmca
10 Replies

10. Shell Programming and Scripting

Creating a tabulated file from content of 2 or more files

Hi all I need specific fields from a file to be tabulated into a single file. I have a file with the following :- FIELD1 InfoA FIELD2 InfoB FILED3 InfoC FIELD1 InfoD FIELD2 InfoE FIELD3 InfoF The output... (2 Replies)
Discussion started by: jhansrod
2 Replies
Login or Register to Ask a Question