how to replace a word starting with certain characters on certain lines?
Tag : unix , By : Cowtung
Date : March 29 2020, 07:55 AM
Hope that helps I am trying to use SED command to replace/remove rs numbers from my file. I have a VCF file: , You can try with this, Ex: sed -i 's/\(^[^#].*\)rs[0-9]\+\( .*\)/\1rs.\2/' test.vcf
sed -i "/^[^#]/s/rs[0-9]\+/rs./g" test.vcf
##reference=file:/hs37d5.fasta
#rs145599635 C T 153.34 .
#1 10234 rs145599635 C T 153.34 .
#CHROM POS ID REF ALT QUAL FILTER INFO FORMAT SC_PCHD5235298
1 10234 rs145599635 C T 153.34 .
|
Check for lines in txt file starting with particular word and count the occurences
Tag : vba , By : Arun Thomas
Date : March 29 2020, 07:55 AM
With these it helps I've been trying to check if a given txt file has lines that start with a particular word. I then want to count the number of lines that start with that word. Though I can't quite get it right, I do think I'm somewhat close with the check. Any and all help are much appreciated! Here's my code so far , Robert, use the .ReadLine method on your object variable. Dim numLines as Long: numLInes = 0
Dim strSearch as string '## the value you're searching for
strSearch = "Steve!" '## MOdify as needed
Do While Not objfil3.AtEndofStream
If Left(objfil3.ReadLine, Len(strSearch)) = strSearch Then
numLines = numLines + 1
Else:
End If
Loop
MsgBox objFil3 & " contains " & numLines & " beginning with " & strSearch
|
Counting lines starting with a certain word
Date : March 29 2020, 07:55 AM
like below fixes the issue How to count the number of lines in a text file starting with a certain word? , Try this:- awk '/^yourwordtofind/{a++}END{print a}' file
|
How to KEEP only the last line of consecutive lines starting with the same word?
Date : March 29 2020, 07:55 AM
it helps some times See this thread : How to remove the second line of consecutive lines starting with the same word? , With sed: sed '/^TITLE/ { :a $! { N; /\nTITLE/ { s/.*\n//; ba; }; }; }' filename
/^TITLE/ { # if a line begins with TITLE
:a # jump label for looping.
$! { # unless we hit the end of input (in case the file
# ends with title lines)
N # fetch the next line
/\nTITLE/ { # if it begins with TITLE as well
s/.*\n// # remove the first
ba # go back to a
}
}
}
|
sed: how to match lines starting with word but not ending with another word
Tag : sed , By : Longchao Dong
Date : March 29 2020, 07:55 AM
wish help you to fix your issue suppose I want to add the word "end" to each line starting with "start". However if the word "end" is already at the end of the line; no need to add it again. So how do I get from: , Use the following approach: sed -i '/ end$/! s/^start .*$/& end/' testfile
awk '{print ($1 == "start" && $(NF) != "end") ? $0" end" : $0}' testfile
|