Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

bash location of substring match within string

# Basic syntax:
grep search_string your_file | awk '{ print index($0, "search_string") }'
# Where:
#	- grep finds the lines in your_file that contain the search_string
#	- the awk index function returns the 1-based index of the search_string
#		within the entire string (which is given by $0 in awk)

# Example usage:
# Say you have a file with the following DNA sequences and want to know where
# the substring CTGCAGTAAG appears within them
CACTATAGGGCTGCAGTAAGCGCGTCGC
CTATAGGGCTGCAGTAAGCGCGTCGCGG
CAATAGGGCTGCAGTAAGCGCGTCGCTT
CACTATAGGGCTGCAGTAAGCGCGTCGC
CACTGGGCTGCAGTAAGCGCGTCGCCCC
CATAGGGCTGCAGTAAGCGCGTCGCGGG
CACTATAGGGCTGCAGTAAGCGCGTCGC
# running:
grep CTGCAGTAAG your_file | awk '{ print index($0, "CTGCAGTAAG") }'
# would return:
11
9
9
11
8
8
11

# Example usage 2:
# If you want to get the frequency of each index sorted from high to low,
# you could run a command like:
grep CTGCAGTAAG your_file | awk '{ print index($0, "CTGCAGTAAG") }' | sort | uniq -c | sort -nr
3 11
2 9
2 8
Comment

PREVIOUS NEXT
Code Example
Shell :: add or remove samba user 
Shell :: how to download utorrent in kali linux 
Shell :: heroku set app name from cli 
Shell :: delete cash on ubuntu 
Shell :: python.h missing 
Shell :: kill process at a port ubuntu 
Shell :: gcloud select project 
Shell :: firebase deploy hosting only command 
Shell :: ubuntu server does not run scripts 
Shell :: jq windows 
Shell :: django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty 
Shell :: requires pyqtwebengine<5.13, which is not installed. 
Shell :: filmora 10 crack download without watermark 
Shell :: how to turn off windows license will expire soon 
Shell :: install git on wsl2 ubuntu 
Shell :: check memory type 
Shell :: jupyter notebook allow root 
Shell :: connect vm to cloud storage gcp 
Shell :: Error: Fetching /usr/local/Homebrew/Library/Taps/commands/homebrew-pup failed! 
Shell :: how to download youtube playlist ubuntu 
Shell :: binding a mac to AD terminal 
Shell :: refs/heads/master:refs/heads/master [rejected] (non-fast-forward) 
Shell :: kill server on port mac 
Shell :: awk lowercase 
Shell :: how to install prompt-sync in node js 
Shell :: The requested URL was not found on this server. Apache/2.4.41 (Ubuntu) Server at Port 80 
Shell :: magento 2 reindex command line 
Shell :: start apache service 
Shell :: update prisma latest version 
Shell :: linux combine zipped files 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =