create multiple files from one file
Hi all,
I have a file called file1.txt like: KEGG_1 Features selected: V2 1.00 V6 1.00 V9 1.00 V13 2.00 V36 2.00 KEGG_2 Features selected: V2 1.00 V3 1.00 V8 1.00 V11 1.00 V45 1.00 V55 1.00 KEGG_3 Features selected: V9 1.00 V10 2.00 V18 1.00 V29 1.00 And I want to create multiple files like: KEGG_1.txt Features selected: V2 1.00 V6 1.00 V9 1.00 V13 2.00 V36 2.00 KEGG_2.txt Features selected: V2 1.00 V3 1.00 V8 1.00 V11 1.00 V45 1.00 V55 1.00 and KEGG_3.txt Features selected: V9 1.00 V10 2.00 V18 1.00 V29 1.00 I have written the following perl script: Code:
#!/usr/bin/perl "Could not open file KEGG_1 for output. at line 27, <IN> line 2538." could someone help me? I cannot understand why? thanks a lot! |
You aren't removing the newline.
Code:
my $key =$lines; |
Try adding this before the output line:
touch $key |
In addition, may I suggest a simple awk alternative?
Code:
awk '/KEGG/{file=($0 ".txt")}!/KEGG/{print > file}' file1.txt Code:
#!/bin/bash |
also in bash
Code:
cat sasanthi.txt | while read line; do if [ "`echo $line | grep KEGG`" ]; then f=$line; else echo $line >> $f.txt; fi; done |
thanks a lot! :)
|
All times are GMT -5. The time now is 06:16 PM. |