select and replace only those string which is followed by \tab


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers select and replace only those string which is followed by \tab
# 1  
Old 09-28-2012
Question select and replace only those string which is followed by \tab

Hi

I have a number of sequences and a string occurs a number of times in that sequence.

How can I select and replace only those strings which are followed by \tab.

for eg :
my sequence looks like :

string0 positive cd parent=string0 id =121 string0
string0 negative ef parent= string0 id =121 string0

I want it to look like
char7 positive cd parent=string0 id =121 string0
char7 negative ef parent= string0 id =121 string0

I want to replace string0 by char7 but only for those followed by \tab
i dont want to replace the string0 in parent and in that id

I am very new into programming so would like some command which is easy to understand Smilie

Thanks a lot!!
# 2  
Old 09-28-2012
Try the below example:
Code:
$ cat t
string0 positive cd parent=string0 id =121 string0
string0 negative ef parent= string0 id =121 string0

$ sed 's/^string0\t/char7\t/' t
char7   positive cd parent=string0 id =121 string0
char7   negative ef parent= string0 id =121 string0

This User Gave Thanks to spacebar For This Post:
# 3  
Old 10-04-2012
Thanks it worked!!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Replace space by tAB

My file looks like 3 33 210.01.10.0 2.1 1211 560 26 45 1298 98763451112 15412323499 INPUT OK 3 233 40.01.10.0 2.1 1451 780 54 99 1876 78787878784 15423210199 CANCEL OK Aim is to replace the spaces in each line by tab Used: sed -e 's/ */\t/g' But I get output like this... (3 Replies)
Discussion started by: sa@@
3 Replies

2. Shell Programming and Scripting

How to replace blank tab with zero in a file?

hi, i need to replace a blank tab output in a file to zero. input file: 2015/08/04 00:00:00 171 730579 27088 <blank> 3823 30273 1621778 ... (6 Replies)
Discussion started by: amyt1234
6 Replies

3. Shell Programming and Scripting

SED - Unable to replace with <tab>

Hello All, I have this file with the below contents 1|2|3|4| this|that|which|what| when I use, sed 's/|/\t/g' infile I get, 1t2t3t4t thistthattwhichtwhatt Why is this?? :confused: :wall: (13 Replies)
Discussion started by: PikK45
13 Replies

4. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

5. Shell Programming and Scripting

replace row separated by tab

Dear users, I have this problem, this is the example: 123 (tab) A (tab) B (tab) C (tab) 456 where the (tab) is actually the \t delimiter. I need to replace the A B and C for D E and F, this is: 123 (tab) D (tab) E (tab) F (tab) 456 The thing is that my file is quite long and this... (2 Replies)
Discussion started by: Gery
2 Replies

6. UNIX for Dummies Questions & Answers

Replace tab or any spaces with "

my content: samaccountname employeeid useraccountcontrol description i want it to look like this: "samaccountname","employeeid","useraccountcontrol","description" (2 Replies)
Discussion started by: tjmannonline
2 Replies

7. Shell Programming and Scripting

Replace with tab

I have text file, i want to replace all the charecters with tab. suppose: cat abc.txt dfjkdf dfdfd fd fd the output should have 4 lines and each line will have 1 tab. Thanks :confused: (2 Replies)
Discussion started by: javeed7
2 Replies

8. Shell Programming and Scripting

replace comma(,) with Tab

hi all, i have a file with commas(,). i want to replace all the commas with tab(\t). Plz help...its urgent... (3 Replies)
Discussion started by: vikas_kesarwani
3 Replies

9. Shell Programming and Scripting

Replace a Pipe with tab

i have a file which contains text as shown below.... aaa|bbb|ccc|ddd| cccc|ddddd|eeeee|ffffff want to convert pipe symbol to tab like aaaa bbbb cccc ddddd ccccc ddddd eeeee ffffffffff i tried with sed sed 's/|/\t/g' file_name ...but i could not... (1 Reply)
Discussion started by: srikanthus2002
1 Replies

10. UNIX Desktop Questions & Answers

replace tab with space

How do I replace a tab with a space in scripts using sed/awk ? (1 Reply)
Discussion started by: avnerht
1 Replies
Login or Register to Ask a Question