Adding lines to files based on file extension


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Adding lines to files based on file extension
# 1  
Old 06-29-2010
Adding lines to files based on file extension

I have posted this before but did not get many replies, so here it goes again.
I have several files name like this
Quote:
Pat1.1a
Patient32.1a
Pat16.3
Sample76.4
Pat243.5
Pat101.1a
Individual33.6
Pat93.2
Pat5.1b
If the file extension is 1a, I woould like to add at the beggining of the file the following sequence
Quote:
>Reference1a
AGCATGACGATCAGTGTGCGGGTGA
If the file extension is 1b, thn the entry that should be added is the next one
Quote:
>Reference1b
AGCATGTGTGCGGGTGA
So on and so forth.
I came out with the following code, which is working, but I was hoping there was a way to do the same thing using awk
Code:
#!/bin/sh
for f in *.1a
do
printf ">Reference1a\nTTGATGTGCCAACTGCGCAAATAGCAGCAGCACTACCAGGACCTTCGCCCA\n" | cat - ${f} > Converted${f}
done
for i in *.1b
do
printf ">Reference1b\nTTGATGTGCCTACCAGGACCTTCGCCCA\n" | cat - ${i} > Converted${i}
done
for e in *.3
do
printf ">Reference3\nTTGATTCGCCCA\n" | cat - ${e} > Converted${e}
done

Any ideas?
Thansk!

---------- Post updated at 08:27 PM ---------- Previous update was at 05:25 PM ----------

Anyone?

Last edited by Xterra; 06-29-2010 at 06:49 PM..
# 2  
Old 06-29-2010
How about:
Code:
awk 'FNR==1{f="Converted"FILENAME; printf p>f} {print>f}' p=">Reference1a\nTTGATGTGCCAACTGCGCAAATAGCAGCAGCACTACCAGGACCTTCGCCCA\n" *.1a
awk 'FNR==1{f="Converted"FILENAME; printf p>f} {print>f}' p=">Reference1b\nTTGATGTGCCTACCAGGACCTTCGCCCA\n" *.1b
awk 'FNR==1{f="Converted"FILENAME; printf p>f} {print>f}' p=">Reference3\nTTGATTCGCCCA\n" *.3

This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 06-30-2010
Scrutinizer

It's much better.
Thank you very much!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copy files based on specific word in a file name & its extension and putting it in required location

Hello All, Since i'm relatively new in shell script need your guidance. I'm copying files manually based on a specific word in a file name and its extension and then moving it into some destination folder. so if filename contains hyr word and it has .md and .db extension; it will move to TUM/HYR... (13 Replies)
Discussion started by: prajaktaraut
13 Replies

2. Shell Programming and Scripting

Conditional deletion of files based on extension

Hello All, I have some files like file, file.chk, file.sem and file.temp in huge. I would like to delete some files based on following criteria. 1. Unconditionally delete .sem and .temp files 2. If we found the actual file, don't remove .chk file, otherwise remove .chk file as well for... (5 Replies)
Discussion started by: VasuKukkapalli
5 Replies

3. UNIX for Dummies Questions & Answers

Display the .csv extension files based on .done extension fine

Hi All, I want to fetch the files based on .done file and display the .csv files and Wil take .csv files for processing. 1.I need to display the .done files from the directory. 2.next i need to search for the .Csv files based on .done file.then move .csv files for the one directory ... (2 Replies)
Discussion started by: girija.g6
2 Replies

4. Shell Programming and Scripting

Delete specific lines from files based on another file

I have some text files in a folder named ff as follows. I need to delete the lines (in-place editing)in these files based on another file aa.txt. 32bm.txt: 249 253 A P - 0 0 8 0, 0.0 6,-1.4 0, 0.0 2,-0.4 -0.287 25.6-102.0 -74.4 161.1 37.1 13.3 10.9 250... (2 Replies)
Discussion started by: aden
2 Replies

5. Shell Programming and Scripting

Generate files from one file based on lines

Hi Friends, I have a file1 file1.txt 1ABC 13478 aqjerh 473 343 2hej 478 5775 24578 23892 3fhd fg 847 brjkb f99345 487 4eh ehjk 84 47589 8947 234 5784 487 738 52895 8975 6 57489 eghe9 4575 859479 7fnbd 4y5 4iuy 458 h irh 8fjdg 74 7845 8475 5789 94yr 48yr 4hr erhj reh... (3 Replies)
Discussion started by: i150371485
3 Replies

6. Shell Programming and Scripting

Adding number before file extension

Hi , I have a file which has a line starts with $segment_name and has the below data source data $Segment_Name = 123.ABC.123.01.txt $Segment_Name = 123.ABC.ABC.txt $Segment_Name = 123.ABC.12A3.txtMy target data should be $Segment_Name = 123.ABC.123.01.txt $Segment_Name =... (2 Replies)
Discussion started by: shruthidwh
2 Replies

7. Shell Programming and Scripting

Adding the data before file extension

HI , I have a file with multiple lines like below, I need to check on column starting with #prototype if it has the .Number.txt extension do nothing else add 1.txt extension. Source data Jdbc_app_data :- sample data #prototype= sample data from test.1.txt application_id=122135... (4 Replies)
Discussion started by: gaur.deepti
4 Replies

8. Shell Programming and Scripting

Adding lines to files based on their names

I have several files on a folder something like this: If the file starts with 1a, I would like to add the following at the very beggining of the file If the file starts with 1b then I should add the following For files starting with 6 So on and so forth. Thus, at the end each file will... (18 Replies)
Discussion started by: Xterra
18 Replies

9. Shell Programming and Scripting

How to split a file with adding sequence number and extension.

I have a file name -HRCFTSIN05PLA1602100430444444 my requirement is to split the file in 10000 count each file and to add sequence number.rch at the end of each file. output should be in this format HRCFTSIN05PLA160210043044444401.rch HRCFTSIN05PLA160210043044444402.rch... (4 Replies)
Discussion started by: abhigrkist
4 Replies

10. UNIX for Dummies Questions & Answers

deleting lines from a delimited files based on a 2nd file

I need a little help... I have a file with 3 fields, Time/Date, IP address, UniqueID I have a 2nd file of UniqueIDs. I want to either (which ever is easier): 1. delete entries in file 1 that have a UniqueID in file 2 2. create a new file with the fields from File 1, excluding the... (4 Replies)
Discussion started by: goldie363
4 Replies
Login or Register to Ask a Question