Selective replace


 
Thread Tools Search this Thread
# 1  
Selective replace

i have a large sequence of format

Code:
sat_1_g3_g_0_8540         .       A     1       15501   .       .       .       ID=sat_1_g3_g_0_8540;parentName=sat_1_g3_g_0_8540;Al=sat_1_g2_g_0_8540;
sat_1_g3_g_2_8510         .       C     1       25501   .       .       .       ID=sat_1_g3_g_2_8510;parentName=sat_1_g3_g_2_8510;Al=sat_1_g1_g_2_8510;

I want it to look like
Code:
string_8540       .       A     1       15501   .       .       .       ID=sat_1_g3_g_0_8540;parentName=sat_1_g3_g_0_8540;Al=sat_1_g2_g_0_8540;
string_8510       .       C     1       25501   .       .       .       ID=sat_1_g3_g_2_8510;parentName=sat_1_g3_g_2_8510;Al=sat_1_g1_g_2_8510;

i dont want the names to be replaced in the ID, parent name and AL column .
I tried doing selective replace using a tab as a function but it still didnt work.
The command I used is
Code:
sed 's/^sat_1_g3_g_0\t/string\t/' infile >sortedfile
sed 's/^sat_1_g3_g_2\t/string\t/' infile >sortedfile

Please tell how can i correct it.

Thanks

Moderator's Comments:
Mod Comment Please use code tags next time for your code and data.

Last edited by radoulov; 01-14-2013 at 05:26 PM..
# 2  
Code:
sed 's/sat_1_g3_._./string/' infile

# 3  
Code:
sed 's/^sat_1_g3_g_[02]/string/' infile >sortedfile

should do what you want.
Note, however, that sortedfile is not sorted (at least not on field1).
# 4  
what does the 2 indicate in the above mentioned code?

Code:
sed 's/^sat_1_g3_g_[02]/string/' infile >sortedfile


Last edited by Scrutinizer; 01-20-2013 at 02:12 AM.. Reason: code tags
# 5  
Quote:
Originally Posted by siya@
what does the 2 indicate in the above mentioned code?

sed 's/^sat_1_g3_g_[02]/string/' infile >sortedfile
The string between the first two / characters in a sed s(ubstitute) command is a basic regular expression. In a BRE the sequence [02] will match a 0 or a 2. And the character ^ at the start of a BRE says to match the BRE that follows only if it occurs at the start of a line. So the s command shown here will replace the string sat_1_g3_g_0 at the beginning of a line or the string sat_1_g3_g_2 at the beginning of a line with the string string.
# 6  
Just an addition to this post
if my sequence looks like this

Code:
string_8540       .       FFF     1       15501   .       .       .       ID=sat_1_g3_g_0_8540

string_8510       .       FFF     1       25501   .       .       .       ID=sat_1_g3_g_2_8510

and I want to replace the third column(ie replace FFF) by seq .

how can i replace only a particular column .. should i use a tab option

"sed \t "

Thanks

---------- Post updated at 07:37 PM ---------- Previous update was at 07:35 PM ----------

I only want to replace the 3rd column entries (FFF by seq)

There might be other places where FFF might be present in the file .I dont want to replace them.

I hope I m not confusing.

ThanksSmilie

Last edited by Scrutinizer; 01-20-2013 at 02:12 AM.. Reason: code tags
# 7  
Using awk
Code:
awk '$3=="FFF"{$3="seq"}1' infile

 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Selective replace and delete

Hi My input file looks like this: >BAHMI01000090.1 Details of the shopping list 9800 item00090, whole set of listed artifacts and objects >BAHMI01050012.1 Details of the shopping list 9800 item02310, whole set of listed artifacts and objects >BAHMI01070078.1 Details of the shopping list ... (5 Replies)
Discussion started by: sonia102
5 Replies

2. UNIX for Dummies Questions & Answers

SQL selective replace

Hi I have a table which looks like this id | name | length | clone | null 1 | string 1 | 12345643 | string 1 | NULL | 2 | string 2 | 2345612 | string 2 | NULL | 3 | string 3 | 3421556 | string 3 | NULL | 4 | string 4 | 1236742 | string 4 | NULL | 5 | string 5 | 2312677 | string 5 | NULL |... (2 Replies)
Discussion started by: rsi.245
2 Replies

3. Shell Programming and Scripting

Selective Replace awk column values

Hi, I have the following data: 2860377|"DATA1"|"DATA2"|"65343"|"DATA2"|"DATA4"|"11"|"DATA5"|"DATA6"|"65343"|"DATA7"|"0"|"8"|"1"|"NEGATIVE" 32340377|"DATA1"|"DATA2"|"65343"|"DATA2"|"DATA4"|"11"|"DATA5"|"DATA6"|"65343"|"DATA7"|"0"|"8"|"1"|"NEG-DID"... (3 Replies)
Discussion started by: sdohn
3 Replies

4. UNIX for Dummies Questions & Answers

Selective Replacements: Using sed or awk to replace letters with numbers in a very specific way

Hello all. I am a beginner UNIX user who is using UNIX to work on a bioinformatics project for my university. I have a bit of a complicated issue in trying to use sed (or awk) to "find and replace" bases (letters) in a genetics data spreadsheet (converted to a text file, can be either... (3 Replies)
Discussion started by: Mince
3 Replies

5. Shell Programming and Scripting

Selective grep

I have to grep out only email address from a column. It has characters appended and prepended F=<sss1@domain.com> <sss2@domain.com> (sss3@domain.com) <sss4@domain.com> Whatever added before and after email, I should be able to grep out only emails. (9 Replies)
Discussion started by: anil510
9 Replies

6. UNIX for Dummies Questions & Answers

Help with selective ls

Hi all :wall: Can anyone advise how do I use ls to do a selective amd sorted listing of file that I want to have as below? Am looking for files that are named as log_<nnnn>.txt, where <nnnn> are numeric, i.e. I want to have a listing sorted from the newest to the oldest of files that... (7 Replies)
Discussion started by: newbie_01
7 Replies

7. UNIX for Dummies Questions & Answers

selective grep

Hello, I have been using the command below for file manipulation. while read A B; do grep $f1; done < f2 > f3 So, if a certain string is found in f2 (for ex; DOG243435) and it is also present in f1, then print that string plus the contents of the line in which it was found onto f3. ... (6 Replies)
Discussion started by: verse123
6 Replies

8. Shell Programming and Scripting

selective printing

hi all from below text "abcd,SYS_12345,xyz,PQR, ," I want to print only "abcd,SYS,xyz,PQR, ," i.e. taking only first three 3 chars from 2 string of comma separated file thanks (4 Replies)
Discussion started by: JoeColeEPL9
4 Replies

9. UNIX for Advanced & Expert Users

Selective Umask

Hi, We have umask 022 in /etc/profile for security reasons. But I want have some other umask for selected users. how to achieve this? Regards (3 Replies)
Discussion started by: baanprog
3 Replies

10. Shell Programming and Scripting

echo is selective?

i tried to ask about this earlier, but didn't explain well enough. From a script, i issue the following: echo `pgp --encrypt filename --recipient public-key` The result is perfect. The encrypted file is in the directory just as if i'd issued the pgp command from the command line. However,... (0 Replies)
Discussion started by: rgard
0 Replies

Featured Tech Videos