Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

awk get index of matching substring

# 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 :: install tor browser on kali linux 
Shell :: convert biom to tsv 
Shell :: install werkzeug 
Shell :: php enable module 
Shell :: linux set env permanent 
Shell :: start mongod ubntu 
Shell :: update all snap packages 
Shell :: firebase deploy only hosting command 
Shell :: # /bin/bash meaning 
Shell :: install jq in windows 
Shell :: telegram on arch linux 
Shell :: libevent ubuntu install 
Shell :: angular install version 12 
Shell :: kubectl delete pods 
Shell :: shell shortcuts 
Shell :: check ram type 
Shell :: add hp printer linux 
Shell :: install brave fedora 
Shell :: brew error 
Shell :: "git reset –- soft head^" 
Shell :: ssh tunel map 
Shell :: npm steps 
Shell :: release a port in mac 
Shell :: change git default branch 
Shell :: how to install modules from requirement.txt 
Shell :: npm Error: EACCES: permission denied, scandir 
Shell :: find which process is using port mac 
Shell :: mongodb create collection 
Shell :: installing nmap on kali linux 
Shell :: shell combine gzipped files 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =