Replace names in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace names in a file
# 1  
Old 10-01-2013
Replace names in a file

Hi, I have a file like this:
Code:
>Contig1
TTTTCATCAGCAATAGGTGCCTTCAACAAGTTTGAGAATTTTTTACACATGACTACAGGG
CACGTGCACAATGTTTTGAGCACTGCCAATGTCGTCTTTTCTTCCCTGCTGATTCTATTT
AGCTAGATTCACTTTGTTTCCAAAAAACGACAACAAATTCCAAGGTGTACCAAGGTGTAT
>Contig2
CCCGTAGTAAAGATCAAAACTATCCCCTGCTGTATTCTCAACCAAATCCAACAAACTCTC
GTACCCTTTTGTATTGATTGGCGTAGACTCCAATTTCAACGTCTCCAACACTCTCCCAAC
AGTATGTGTAATAAACTGTGATCCTGCTGCATACTTATCTTGGTCTTGACAACTCATTTC
CAACATTTTACATCCCTCTCTAGCAAAAATATCAAGAAATCTTTTACACCTATCAATTCT
TGATTTCTCTTTGCCAATTCTAACATTCTCATACACAAATTGGAGATCATCCCATCCAAG
ATTGGCACTTTGAGGAC
....
>Contig34172
AAAAATTTTGAATTTTCATTTATTTAAGTAAAGCTGTGTCAAATAGTTAATATCTTGACA
CCTTCAATATATAATTAATCCAAGATATAAGATTAAAGAAATTACAAGAACGCTGAAAAT
TTGGTGGATATAACAATGACCAAATATTATTTAAGGTAACCACTGCTCTTTCTTGAAAAA
GCAGCCTCCATTTTCATAGGATTTCTTGAGGAAACGCCGTCTCTCTGGAATTGCATTGCA
GACGACAGCATTTCCATTTTCAACATTGAAACCCAT
>contig00002  length=24  numreads=36  gene=isogroup00001  status=it_thresh
TGTATACCTTCCTAAAGGCCTCAA
>contig00004  length=30  numreads=51  gene=isogroup00001  status=it_thresh
TATTGTGTATCCAAATGATGCTTATGATGA
>contig00013  length=37  numreads=25  gene=isogroup00001  status=it_thresh
TGAAGCTCTCTGCCTGTTTTGCAAGCATGCCTTCAAG
.....

How could i replace the name from ">contig00002 length=24 numreads=36 gene=isogroup00001 status=it_thresh" to ">Contig34173". Same for the later "contigs"....

Thanks,
Vivi
# 2  
Old 10-01-2013
For the sample you provided, this should work:
Code:
awk '/^>Contig/ {i=$1; sub (/>Contig/,"", i)} /^>contig/ {print ">CONTIG"++i; next} 1' file

# 3  
Old 10-01-2013
Rudic, Thanks!!!

If i want to replace
Code:
contig00002 length=24 ...

to
Code:
contig00002_newbler

,
Code:
contig00004 length=30 ...

to
Code:
contig00004_newbler

, and so on.

What should i do??
# 4  
Old 10-02-2013
Change
Code:
/^>contig/ {print ">CONTIG"++i; next}

to
Code:
/^contig/ {$1=$1"_newbler"}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find matching file in bash with variable file names but consisent prefixs

As part of a bash the below line strips off a numerical prefix from directory 1 to search for in directory 2. for file in /home/cmccabe/Desktop/comparison/missing/*.txt do file1=${file##*/} # Strip off directory getprefix=${file1%%_*.txt} ... (5 Replies)
Discussion started by: cmccabe
5 Replies

2. Shell Programming and Scripting

Exclude certain file names while selectingData files coming in different names in a file name called

Data files coming in different names in a file name called process.txt. 1. shipments_yyyymmdd.gz 2 Order_yyyymmdd.gz 3. Invoice_yyyymmdd.gz 4. globalorder_yyyymmdd.gz The process needs to discard all the below files and only process two of the 4 file names available ... (1 Reply)
Discussion started by: dsravanam
1 Replies

3. Shell Programming and Scripting

Change the file name and copy old file content to new file names.

Hi, I have a files in a directory as below :- ls -1 mqdepth-S1STC02 proc-mq-S1STC01 proc-mq-S1STC02 proc-mq-S1STC03 Whereever i have S1STC i need to copy them into new file with file name S2STC. expected output :- ls -1 mqdepth-S2STC02 proc-mq-S2STC01 proc-mq-S2STC02... (3 Replies)
Discussion started by: satishmallidi
3 Replies

4. Shell Programming and Scripting

Split File by Pattern with File Names in Source File... Awk?

Hi all, I'm pretty new to Shell scripting and I need some help to split a source text file into multiple files. The source has a row with pattern where the file needs to be split, and the pattern row also contains the file name of the destination for that specific piece. Here is an example: ... (2 Replies)
Discussion started by: cul8er
2 Replies

5. Shell Programming and Scripting

How to split a data file into separate files with the file names depending upon a column's value?

Hi, I have a data file xyz.dat similar to the one given below, 2345|98|809||x|969|0 2345|98|809||y|0|537 2345|97|809||x|544|0 2345|97|809||y|0|651 9685|98|809||x|321|0 9685|98|809||y|0|357 9685|98|709||x|687|0 9685|98|709||y|0|234 2315|98|809||x|564|0 2315|98|809||y|0|537... (2 Replies)
Discussion started by: nithins007
2 Replies

6. Shell Programming and Scripting

Replace variable names in text file with its value

Hi I have a text file (mytext.txt), the content of which is as following: My name is <@MY_NAME@> and my age is <@MY_AGE@> . Now i have another property file (myprops) which is as following: MY_NAME=abcdefgh MY_AGE=000000 I was wondering, how can i replace the tags of mytext.txt, with its... (1 Reply)
Discussion started by: vigithvg
1 Replies

7. Shell Programming and Scripting

Searching for file names in a directory while ignoring certain file names

Sun Solaris Unix Question Haven't been able to find any solution for this situation. Let's just say the file names listed below exist in a directory. I want the find command to find all files in this directory but at the same time I want to eliminate certain file names or files with certain... (2 Replies)
Discussion started by: 2reperry
2 Replies

8. UNIX for Dummies Questions & Answers

Find and replace portion of file names

Hey all, So I know you can easily find and replace words and strings in text files, but is there an easy way to find and replace just a sub-portion of text in the file name. For example, in a directory I have tons of file names that start with F00001-0708, and I want to change all the files to... (2 Replies)
Discussion started by: hertingm
2 Replies

9. Shell Programming and Scripting

Reading file names from a file and executing the relative file from shell script

Hi How can i dynamically read files names from a list file and execute them from a single shell script. Please help its urgent Thanks in Advance (4 Replies)
Discussion started by: anushilrai
4 Replies

10. Shell Programming and Scripting

Replace characters in all file names in a particular directory

Hi, I have searched the forum on how to mass replace the file names. We are doing the migration and I am trying to accomplish a task where I have to replace all UNIX scripts in a particular directory that start with bdw to fdm... For example: bdw0110137.sh should be fdm0110137.sh Keep the... (4 Replies)
Discussion started by: madhunk
4 Replies
Login or Register to Ask a Question