Generating a file based on another file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Generating a file based on another file
# 1  
Old 07-07-2010
Generating a file based on another file

I am trying to generate a file like this one
Quote:
;1.0
1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20;
10;10;10;10;10;10;10;10;10;10;10;10;10;10;10;10;10;10;10;10;
>GHL8OVD01BNNCA Freq 4;1;;;;
TAGATGTGCCCGTGGGTTTC
>GHL8OVD01CMQVT Freq 15;1;;;;
TTGATGTCGTGGGTTTCCCG
>GHL8OVD01CMQVT Freq 50;1;;;;
TTGATGTGCCAGTTTCCCGT
>GHL8OVD01CMQVW Freq 700;1;;;;
TTGATGTGTCCCGTCGACAC
>GHL8OVD01A45V3 Freq 9;1;;;;
TTGATTCCCGTCGACACCGG
>GHL8OVD01AV2U9 Freq 17;1;;;;
TTGATGTGCCAGCTTTCGCG
Based on this other file
Quote:
>GHL8OVD01BNNCA Freq 4
TAGATGTGCCCGTGGGTTTC
>GHL8OVD01CMQVT Freq 15
TTGATGTCGTGGGTTTCCCG
>GHL8OVD01CMQVT Freq 50
TTGATGTGCCAGTTTCCCGT
>GHL8OVD01CMQVW Freq 700
TTGATGTGTCCCGTCGACAC
>GHL8OVD01A45V3 Freq 9
TTGATTCCCGTCGACACCGG
>GHL8OVD01AV2U9 Freq 17
TTGATGTGCCAGCTTTCGCG
The first part at the very top ( ;1.0) is a constant so it does not change from file to file -that part is not a problem. My problems start with the second line, as you can see those are consecutive numbers (1;2;3; etc) representing the length of those sequences (In this case 20, all sequences are the same length). Then, the 3rd line has 20 "10;" one after another, just like above the number of "10;" is = to the sequence length. The rest of the file is almost identical to the original with the only difference that I need to add a pattern to each ID (;1;;;Smilie. I need to do some manipulation afterwards but that part is pretty much taken care of.
Any help will be greatly appreciated.

Last edited by Xterra; 07-08-2010 at 12:02 PM..
# 2  
Old 07-08-2010
Try...
Code:
awk 'BEGIN {
          n = 20
          for (i = 1; i <= n; i++) {
               x = x i ";"
               y = y "10;"
          }
          print ";1.0"
          print x
          print y
     }

     {
          if ($0 ~ /^>/)
               print $0 ";1;;;;"
          else
               print $0
     }
     ' file1 > file2

# 3  
Old 07-08-2010
Code:
awk 'NR==2{print length($0)}' file | awk 'BEGIN{getline;n=$0;print ";1.0";for (i=1;i<=n;i++) printf "%s;",i;
printf "\n";for (i=1;i<=n;i++) printf "10;";printf "\n"}!/^>/{sub("$",";1;;;;");print;next}1' - file

This User Gave Thanks to bartus11 For This Post:
# 4  
Old 07-08-2010
Can you explain how you change
Code:
>GHL8OVD01BNNCA Freq 4
TAGATGTGCCCGTGGGTTTC

to

Code:
>GHL8OVD01BNNCA Freq 4;1;;;;
AGTGCCCGTGGGTTTC

The red parts have different length.
# 5  
Old 07-08-2010
bartus11

Thanks a lot!
I only need to chage where the pattern ";1;;;;" is being added. It should be next to the Freq value rather than the end of the sequence. I will try to modify your code accordingly.

Last edited by Xterra; 07-08-2010 at 12:42 PM..
# 6  
Old 07-08-2010
Just remove "!", so it looks like:
Code:
awk 'NR==2{print length($0)}' file | awk 'BEGIN{getline;n=$0;print ";1.0";for (i=1;i<=n;i++) printf "%s;",i;
printf "\n";for (i=1;i<=n;i++) printf "10;";printf "\n"}/^>/{sub("$",";1;;;;");print;next}1' - file

# 7  
Old 07-08-2010
My bad!

I had a problem with the input file and that's why it was not working when I tried without the "!".
Thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Generating xml file from UNIX

i have a unix script which generates the csv file. the data in csv file is dynamic. how can i convert/move the data from csv file to xml. please suggest (1 Reply)
Discussion started by: archana25
1 Replies

2. Shell Programming and Scripting

Check to see if a file is generating

Hi guys, I am pulling my hair out here. I have a file that comes in, once it finishes i want to move it to a new location. This sounds all very easy but my solution is failing and moves the file before it has finished generating. isrun=`ps -ef | grep -i filename | grep -v grep | wc -l` ... (8 Replies)
Discussion started by: twinion
8 Replies

3. UNIX for Dummies Questions & Answers

Generating a CSV file from a text file

Hi Guys, I have a simple request. I have a file in w3c format. Each file has 2 header lines. Rest of the lines are 16 columns each. They are separated by Tab. I need to discard the first 2 lines and then write each column of the txt file into a seperate column of CSV. I tried the command below... (1 Reply)
Discussion started by: tinkugadu
1 Replies

4. Shell Programming and Scripting

Generating file from sqlplus

Hi Frndz, I have req in which i need to run the query stored in some file and then store the resultset of the query in some other file. PFB the code i have written: #----Start job log--- SQLLOG='/opt/app/vertica2/cdr_dev/logs/conn_orac_db.log' ORA_USER='abc' ORA_PASSWD='xyz' ... (7 Replies)
Discussion started by: gnnsprapa
7 Replies

5. UNIX for Dummies Questions & Answers

Generating a Config File

HI, I want to append some configuration statements to the existing file in unix to it's 3 line , 7th line and 28 line. There is a file generated by our system job, to this I need to add some lines as mentioned below. DIR=/usr/CDR - line 3 Source=/usr/src - line 7 Target=/usr/tgt - line... (2 Replies)
Discussion started by: mora
2 Replies

6. Shell Programming and Scripting

Generating a passwordlist based on rules

Hy there! Some time ago I encrypted the harddrive of my notebook. Now, I can't remember it correctly. I want to create a list with all possible combinations of the words I used (I still remember all the words....). The password was created like this: ... (1 Reply)
Discussion started by: santiago10k
1 Replies

7. Shell Programming and Scripting

Performance issue in UNIX while generating .dat file from large text file

Hello Gurus, We are facing some performance issue in UNIX. If someone had faced such kind of issue in past please provide your suggestions on this . Problem Definition: /Few of load processes of our Finance Application are facing issue in UNIX when they uses a shell script having below... (19 Replies)
Discussion started by: KRAMA
19 Replies

8. UNIX for Dummies Questions & Answers

Generating different columns from same file

Hi, Our requirement is we have to create file from one file where all the rows from source file is converted into columns of the target file. For example Source file is : Status Report ABC Generated: 2009-05-05 08:49:47 Job start time=2009-05-05 08:43:43 Job end time=2009-05-05... (1 Reply)
Discussion started by: Amey Joshi
1 Replies

9. Shell Programming and Scripting

Ksh - finding pattern in file and generating a new file

I am trying to find for the pattern in first 5 bytes of every line in a text file and then generate a new file with the pattern found. Example: expected pattern is '-' to be serached in first 5 bytes of file only. Input File ab-cd jan-09 ddddd jan09 cc-ww jan09 dsgdq jan-09 ... (2 Replies)
Discussion started by: net
2 Replies

10. Shell Programming and Scripting

Bash Scripts - File generating

Forgive the daft requests - I'm still a learner :D I need a script so that I can test another script (I'm confused already) The script I am looking for should generate a new file in the same directory (called newfile1 or what ever) and also generate text within the new file (Hello world? What... (1 Reply)
Discussion started by: JayC89
1 Replies
Login or Register to Ask a Question