Sponsored Content
Top Forums Shell Programming and Scripting loop through lines and save into separate files Post 302569852 by yifangt on Tuesday 1st of November 2011 07:05:01 PM
Old 11-01-2011
loop through lines and save into separate files

I have two files:
file-gene_families.txt that contains 30,000 rows of 30 columns. Column 1 is the ID column and contains the
Code:
Col1                  Col2  Col3 ...
One gene-encoded CBPs ABC  111 ...
One gene-encoded CBPs ABC  222 ...
One gene-encoded CBPs ABC  212 ...
Two gene encoded CBPs EFC   223 ...
Two gene encoded CBPs EFC   133 ...
Two gene encoded CBPs EFC   103 ...
Two gene encoded CBPs EFC   323 ...
Three gene(encoded) CBPs CGC  20 ...
Four gene/encoded (CBPs) GGH NULL ...
Four gene/encoded (CBPs) GGH 0 ...
Four gene/encoded (CBPs) GGH 1 ... 
Four gene/encoded (CBPs) GGH 2 ...
Four gene/encoded (CBPs) GGH 3 ...
Four gene/encoded (CBPs) GGH 56 ...

and
file-group.list.
Code:
One gene-encoded CBPs
Two gene encoded CBPs
Three gene(encoded) CBPs
Four gene/encoded (CBPs)

I want separate file-gene_families.txt based on the file-group.list using the each line of file-group.list as the file names of the output, substitute these brackets space and slash with hyphen "-".
Code:
One-gene-encoded-CBPs.tmp
Two-gene-encoded CBPs.tmp
Three-gene-encoded-CBPs.tmp
Four-gene-encoded-CBPs.tmp

for example in One-gene-encoded-CBPs.tmp
Code:
One gene-encoded CBPs ABC  111 ...
One gene-encoded CBPs ABC  222 ...
One gene-encoded CBPs ABC  212 ...

Could not get my script working. Can someone help me out?
Code:
#!/usr/bin/bash
IFS=$'\n'
for line in $(cat At-GeneFamily-Unique-group.list)
do
name=$(sed 's/\ |\//-/g' $line)
grep $line gene_families.txt >> $name.tmp
done

Thanks a lot!
YF
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

diff lines from 2 files in a while loop

Okie I have two files. file1 with input asdf_s45 fdsa_s20 jkl_s32 lkj_s3 and file2 with input asdf_s44 fdsa_s19 jkl_s31 lkj_s2 now I have counted the total number of lines in the file and put it in a variable so num_lines=4 now I have a while loop to repeat a diff command... (6 Replies)
Discussion started by: bigboizvince
6 Replies

2. Shell Programming and Scripting

counting the lines of diff files in loop

i have two file. i want to count the lines of each file one by one in loop and compare it. can any one pls help me on this? (1 Reply)
Discussion started by: Aditya.Gurgaon
1 Replies

3. Shell Programming and Scripting

Direct the invalid lines to a separate files

Hi, I have a pipe delimited file with 1 million records. I need to validate each line by counting the number of delimiters, if any line fails to have the specified number of delimiters, taat line has to be sent to a reject file. Kindly suggest. if code provided, it is highly appreciated, and... (22 Replies)
Discussion started by: anandapani
22 Replies

4. Shell Programming and Scripting

Concatenating lines of separate files using awk or sed

For example: File 1: abc def ghi jkl mno pqr File 2: stu vwx yza bcd efg hij klm nop qrs I want the reult to be: abc def ghistu vwx yza jkl mno pqrbcd efg hij klm nop qrs (4 Replies)
Discussion started by: tamahomekarasu
4 Replies

5. Shell Programming and Scripting

extract nth line of all files and print in output file on separate lines.

Hello UNIX experts, I have 124 text files in a directory. I want to extract the 45678th line of all the files sequentialy by file names. The extracted lines should be printed in the output file on seperate lines. e.g. The input Files are one.txt, two.txt, three.txt, four.txt The cat of four... (1 Reply)
Discussion started by: yogeshkumkar
1 Replies

6. Shell Programming and Scripting

Sed save changes to same file in loop

I have got problems saving sed changes to the same file in a loop. Basically I want the delimited value in every line of the file to be set to blank according to the value stored in var. var can be changed anytime. I do not have sed -i and i've tried to mv the file. Any other ideas? My file... (8 Replies)
Discussion started by: alienated
8 Replies

7. Shell Programming and Scripting

Combine the lines from separate text files

Hi All, I have three separate text files which has only one line and i want to combine these lines in one text file which will have three lines. cat file1.txt abc cat file2.txt 1265 6589 1367 cat file3.txt 0.98 0.36 0.5 So, I want to see these three lines in the... (9 Replies)
Discussion started by: senayasma
9 Replies

8. Shell Programming and Scripting

how to write on separate lines?

Hello friends, I have a file "a.txt" its contents ----------------- pid 4075 (caiopr) shmat(1929379932, 0x0000000000000000, 0) = 0x00000000ff030000 (errno 0) pid 4075 (caiopr) shmdt(0x00000000ff030000) = 144 (errno 0) pid 4075 (caiopr) shmctl(1929379932, IPC_RMID) pid 4205 (cau9cli.exe)... (2 Replies)
Discussion started by: Sunusernewbie
2 Replies

9. Shell Programming and Scripting

REGEX to separate paths by whitespace and do a loop

I am trying to do in a single line to take a list of paths separated by whitespace and then loop thru all the paths that were wrote but my regex is not working, I have echo {3} | sed 's/ //g' | while read EACHFILE do ..... But for some reason is only taking always the first path that I... (7 Replies)
Discussion started by: jorgejac
7 Replies

10. UNIX for Beginners Questions & Answers

Awk: output lines with common field to separate files

Hi, A beginner one. my input.tab (tab-separated): h1 h2 h3 h4 h5 item1 grpA 2 3 customer1 item2 grpB 4 6 customer1 item3 grpA 5 9 customer1 item4 grpA 0 0 customer2 item5 grpA 9 1 customer2 objective: output a file for each customer ($5) with the item number ($1) only if $2 matches... (2 Replies)
Discussion started by: beca123456
2 Replies
erl_comment_scan(3erl)					     Erlang Module Definition					    erl_comment_scan(3erl)

NAME
erl_comment_scan - Functions for reading comment lines from Erlang source code. DESCRIPTION
Functions for reading comment lines from Erlang source code. DATA TYPES
comment() = {integer(), integer(), integer(), [string()]} : EXPORTS
file(FileName::filename() (see module file)) -> [Comment] Types Comment = {Line, Column, Indentation, Text} Line = integer() Column = integer() Indentation = integer() Text = [string()] Extracts comments from an Erlang source code file. Returns a list of entries representing multi-line comments, listed in order of increasing line-numbers. For each entry, Text is a list of strings representing the consecutive comment lines in top-down order; the strings contain all characters following (but not including) the first comment-introducing % character on the line, up to (but not including) the line-terminating newline. Furthermore, Line is the line number and Column the left column of the comment (i.e., the column of the comment-introducing % char- acter). Indent is the indentation (or padding), measured in character positions between the last non-whitespace character before the comment (or the left margin), and the left column of the comment. Line and Column are always positive integers, and Indentation is a nonnegative integer. Evaluation exits with reason {read, Reason} if a read error occurred, where Reason is an atom corresponding to a Posix error code; see the module file(3erl) for details. join_lines(Lines::[CommentLine]) -> [Comment] Types CommentLine = {Line, Column, Indent, string()} Line = integer() Column = integer() Indent = integer() Comment = {Line, Column, Indent, Text} Text = [string()] Joins individual comment lines into multi-line comments. The input is a list of entries representing individual comment lines, in order of decreasing line-numbers ; see scan_lines/1 for details. The result is a list of entries representing multi-line comments, still listed in order of decreasing line-numbers , but where for each entry, Text is a list of consecutive comment lines in order of increasing line-numbers (i.e., top-down). See also: scan_lines/1 . scan_lines(Text::string()) -> [CommentLine] Types CommentLine = {Line, Column, Indent, Text} Line = integer() Column = integer() Indent = integer() Text = string() Extracts individual comment lines from a source code string. Returns a list of comment lines found in the text, listed in order of decreasing line-numbers, i.e., the last comment line in the input is first in the resulting list. Text is a single string, contain- ing all characters following (but not including) the first comment-introducing % character on the line, up to (but not including) the line-terminating newline. For details on Line , Column and Indent , see file/1 . string(Text::string()) -> [Comment] Types Comment = {Line, Column, Indentation, Text} Line = integer() Column = integer() Indentation = integer() Text = [string()] Extracts comments from a string containing Erlang source code. Except for reading directly from a string, the behaviour is the same as for file/1 . See also: file/1 . AUTHORS
Richard Carlsson <richardc@it.uu.se > syntax_tools 1.6.7 erl_comment_scan(3erl)
All times are GMT -4. The time now is 09:52 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy