Find and replace with wildcard

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Find and replace with wildcard
# 1  
Old 06-14-2017
Find and replace with wildcard

HI there,

I am trying to find and replace with wildcard with
data

Code:
chr1	69511	69511	A	G	1/1:0,34:791,78,0:78:34	0/1:55,60:1130,0,1513:99:116	1/1:0,28:630,63,0:63:28	0/1:0,34:626,57,0:57:34

To this
Code:
chr1	69511	69511	A	G	homo	hetero	homo	hetero

Where I find and replace 0/1 with wildcard* to hetero
and 1/1 with wildcard* to homo

been experimenting with
Code:
sed 's/0\/1.*/hetero/g' file

but did achieve the desired result
# 2  
Old 06-14-2017
sed does not understand fields / columns without a lot of effort, awk can loop through them.

Loop starts at 6 for efficiency, if the 0/1 can come in any field change it to 1.

Code:
$ awk -F"\t" -v OFS="\t" '{ for(N=6; N<=NF; N++) { if($N ~ /^1\/1:/) $N="homo" ; if($N ~ /^0\/1:/) $N="hetero" } } 1' het.txt

chr1    69511   69511   A       G       homo    hetero  homo    hetero

$

This User Gave Thanks to Corona688 For This Post:
# 3  
Old 06-14-2017
Many thanks
# 4  
Old 06-14-2017
One could also try:
Code:
sed 's,0/1[^[:space:]]*,homo,g
s,1/1[^[:space:]]*,hetero,g' file

If all of your fields are <tab> separated and some fields might contain <space>s, replace each occurrences of the string [:space:] in the above with a literal <tab> character.

If you are using a Solaris/SunOS system, and the above command doesn't work; change sed to /usr/xpg4/bin/sed.
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace String matching wildcard pattern

Hi, I know how to replace a string with another in a file. But, i wish to replace the below string pattern EncryptedPassword="{gafgfa}]\asffafsf312a" i.e EncryptedPassword="<any random string>" To EncryptedPassword="" i.e remove the random password to a empty string. Can you... (3 Replies)
Discussion started by: mohtashims
3 Replies

2. Shell Programming and Scripting

sed replace characters using a wildcard

Hello, I have some data that looks like the following, > <SALTDATA> (OVS0199262) HCl > <IDNUMBER> (OVS0199262) OVS0199262 > <SUPPLIER> (OVS0199262) TimTec > <EMAIL> (OVS0199262) info@timtec.net > <WEBSITE> (OVS0199262) http://www.timtec.net I need to remove the data in... (3 Replies)
Discussion started by: LMHmedchem
3 Replies

3. Shell Programming and Scripting

find command with wildcard directory

I want to look if there is any file inside a specific directory which was modified before 2 days. I wrote the find command, but the problem is there is one directory and that is a random directory generated by unix, so not sure on how to code for that on the find command. find... (5 Replies)
Discussion started by: srini0603
5 Replies

4. UNIX for Dummies Questions & Answers

find and replace

I have a tab-delimited inFile: cat inFile A B C D E F 1 2 3 4 5 6 a b c d e fI would like to replace the first 3 tabs in each row with underscore to get outFile: A_B_C_D E F 1_2_3_4 5 6 a_b_c_d e fhow can I modify the following... (5 Replies)
Discussion started by: jdhahbi
5 Replies

5. Shell Programming and Scripting

Passing wildcard parameters to find via a variable

I have a script to fix permissions which is made up of blocks like: FS_ROOT=/home/shared/Photos FS_EXCLUDE=( \( -path */.webviews -o -path */.thumbnails \) -prune -o ) find $FS_ROOT ${FS_EXCLUDE} -type d -not -perm 2770 -exec chmod 2770 "{}" \; That fragment works as expected, but no matter... (3 Replies)
Discussion started by: mij
3 Replies

6. Shell Programming and Scripting

Find replace a particular string of data with wildcard

Hi I am having a csv file in which lots of data are available wherein i need to find a particular kind of data and replace it with null value. here is the sample data.. I need to find the string starting with 404-064- and up to the first space i have to remove the data and keep the... (4 Replies)
Discussion started by: aemunathan
4 Replies

7. Shell Programming and Scripting

use sed do batch wildcard string replace

Hi, Here is what I want to do I want to search local directory and its sub directory, all the files which contain any string like _12345, then remove this string. String is a combination of _ plus a random integer number. For example, here is one line in a file before <properties... (1 Reply)
Discussion started by: bp5000
1 Replies

8. Solaris

Problem in using wildcard characters in xargs with find

Hi, Under my parent diectory I have directory named "Response" in many of its subfolders. I am interested to see all files with extention .pro in Response Directory. I am giving following command - find . -name "Response" -type d | xargs -i ls -lrt {}/*.pro but it is not giving result. ... (3 Replies)
Discussion started by: sanjay1979
3 Replies

9. Shell Programming and Scripting

Wildcard in Cshell find command

The following command works fine in my cshell script: set Deliverables = `find . -name "eliverables" -print` The following command does not work: set LASFiles = `find . -name "*." -print` In the first example, when tested in an if statement, the script will continue whether a... (3 Replies)
Discussion started by: phudgens
3 Replies

10. UNIX for Dummies Questions & Answers

Find wildcard .shtml files in wildcard directories and removing them- How's it done?

I'm trying to figure out how to build a small shell script that will find old .shtml files in every /tgp/ directory on the server and delete them if they are older than 10 days... The structure of the paths are like this: /home/domains/www.domain2.com/tgp/ /home/domains/www.domain3.com/tgp/... (1 Reply)
Discussion started by: Neko
1 Replies
Login or Register to Ask a Question