Replace other instances except the first one


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace other instances except the first one
# 1  
Old 10-01-2012
Replace other instances except the first one

Hi Friends,

This is my input

Code:
track type=alpha name="omega"
fixedStep chrom=chr10 name="omega"
1
2
3
34
4
4
44
4
4
34
5
5
566
6
66
77
7
7
track type=alpha name="omega"
fixedStep chrom=chr11 name="omega"
9
8
7
9
8
98789
1256
565
876
0
0
0
0
00
97856412
36
65
548
track type=alpha name="omega"
fixedStep chrom=chr12 name="omega"
1212123
5456
8789
4554


Now, my output should be

Code:
track type=alpha name="omega"
fixedStep chrom=chr10 name="omega"
1
2
3
34
4
4
44
4
4
34
5
5
566
6
66
77
7
7
fixedStep chrom=chr11 name="omega"
9
8
7
9
8
98789
1256
565
876
0
0
0
0
00
97856412
36
65
548
fixedStep chrom=chr12 name="omega"
1212123
5456
8789
4554

Basically, leave the first
Quote:
track type=
section. But, replace all other instances of it.

Any thoughts are highly appreciated.

A small hint is that each next line after the
Quote:
track type=
line starts with
Quote:
fixed
.

Thanks in advance
# 2  
Old 10-01-2012
Try:
Code:
awk '!/^track type/;NR==1' file

This User Gave Thanks to bartus11 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Multiple instances of pthread

Suppose I declare pthread_t clear_thread; and then pthread_create(&clear_thread, &detach, clear_message, this); the thread is supposed to go away, perform the service it is intended to procide, and then kill itself. A little while later, I require this service again, so I say ... (2 Replies)
Discussion started by: clerew
2 Replies

2. UNIX for Dummies Questions & Answers

print all instances of sshd

how would i print all the instance of sshd process, sorted based on alphabetical order of user-id. the output should only consist of User-ID of the process and the process name? (1 Reply)
Discussion started by: stefanere2k9
1 Replies

3. Shell Programming and Scripting

replacing all instances in a file

Hi I have some script like this: perl -i -p0e 's/"keyword1-.*?"/"keyword2"/s' file to replace some keyword, but it replaces only the first instance of the keyword how can i get it to replace all instances? thanks! (2 Replies)
Discussion started by: vanessafan99
2 Replies

4. Shell Programming and Scripting

Filtering rows for first two instances of a value

Kindly help me with this problem: My data looks like this: SNPfile.txt CHR_A BP_A SNP_A CHR_B BP_B SNP_B R2 p-SNP_A p-SNP_B 4 172575323 rs17056855 4 172601079 rs11945883 0.119414 0.049972656 0.031050345 4 172575323 rs17056855 4 ... (2 Replies)
Discussion started by: genehunter
2 Replies

5. Shell Programming and Scripting

Can sed replace every 2 instances it finds in a file? Pattern.

My goal is to make a script to find/replace the variable "PORT" with a unique number. Like the following <VirtualHost 174.120.36.236:PORT> ServerName architect.com.ph ServerAlias www.architect.com.ph DocumentRoot /home/architec/public_html ServerAdmin... (16 Replies)
Discussion started by: EXT3FSCK
16 Replies

6. Shell Programming and Scripting

Multiple instances of a job.

Could you please let me know how to create/make a multiple instances of a job/process in ksh(shell scripting). i.e., at present the parent script is calling another child/dependent script for only once. What we want is, the parent script itself has to execute multiple times, and in each one it... (1 Reply)
Discussion started by: Gangegowda
1 Replies

7. Shell Programming and Scripting

How to replace all string instances found by find+grep

Hello all Im performing find + grep operation that looks like this : find . -name "*.dsp" | xargs grep -on Project.lib | grep -v ':0' and I like to add to this one liner the possibility to replace the string " Project.lib" that found ( more then once in file ) with "Example.lib" how can I do... (0 Replies)
Discussion started by: umen
0 Replies

8. Shell Programming and Scripting

detecting multiple instances

Hi Gurus I have a requirement like this. i use solaris OS.. if there are 2 instances of the same ksh file running in the directory, i need to kill the ksh file that started to run latest. suppose ragha.ksh starts running thru cron in abc/xyz directory now ragha.ksh started running by any... (3 Replies)
Discussion started by: ragha81
3 Replies

9. UNIX for Dummies Questions & Answers

Multiple file instances

I am capturing text based reports with a specific program, which works no problem. However, since I send report warehouse output as they are migrated from the database software, on occasion when two capture process' initiate simultaneously, the capture file locks up. Is there a way to setup (in... (1 Reply)
Discussion started by: gozer13
1 Replies

10. UNIX for Advanced & Expert Users

multiple instances of syslogd - is it possible?

I would like to start up multiple instances of syslog daemon. I am having a little difficulty. Is this at all possible? I have separate syslog.conf1.... syslog.conf5 files. I have linked the daemon to separate files syslogd1 ... syslogd5 I have arranged the rcd.2 start/stop scripts for... (9 Replies)
Discussion started by: Gary Dunn
9 Replies
Login or Register to Ask a Question