I have a file with hundreds of lines in it. I wanted to extract anything that matches the following:
KR followed by 4 digits:
example KR1201
Is the closest I've come, and obviously it is not what I want. This would remove all of the items that I want and leave me with the rest of the text. I've tried sed -n and /p' but this doesn't work and I'm confused about the syntax. I know other ways to do this with egrep and grep -w but I want to learn to do it in sed.
The one thing I don't want to do is print the rest of the line; I want only to print the KR1201 or KR followed by 4 digits. There is something missing in my syntax; not sure how to encapsulate the pattern.
As with sort, sed takes pathname operands. Using:
instead of:
wastes system resources, slows down your system for other users who may be sharing your system, and makes your command line run slower.
If you have an input file named list containing:
and you run the command:
using a standards conforming version of sed, you get the output:
The Linux sed man page says:
Quote:
POSIX.2 BREs should be supported, but they aren't completely because of performance problems.
and in the description of the sed s(ubstitute) command says:
Quote:
The replacement may contain the special character & to refer to that portion of the pattern space which matched, and the special escapes \1 through \9 to refer to the corresponding matching sub-expressions in the regexp.
But, there is no other mention of sub-expressions on that man page.
Note that this sed command makes no effort to find more than one occurrence of your pattern if it appears more than once on a single line
This User Gave Thanks to Don Cragun For This Post:
I've learned a lot from your sed/sort tutorials and today was able to solve a sort problem on my own for once after reading all your posts. I thank you for taking the time out of your day to really create detailed posts with examples! This is much more helpful than any textbook!
Hi!
I found and then adapt the code for my pipeline...
awk -F"," -vOFS="," '{printf "%0.2f %0.f\n",$2,$4}' xxx > yyy
I add -F"," -vOFS="," (for input and output as csv file) and I change the columns and the number of decimal...
It works but I have also some problems... here my columns
... (7 Replies)
Hello,
I have a file such as this:
chr1
chr2
chr1
chr2
chr3
chr10
chr4
chr5
chrz
chr1AI want to sort it, I use this command:
sort -k1 -th -n testfilebut I get this output, how can I fix this?
chr1
chr1
chr10
chr1A
chr2
chr2 (3 Replies)
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)
Hello All,
I need to extract lines from a file that contains ALPHANUMERIC and the length of Alphanumeric is set to 16. I have pasted the sample of the lines from the text file that I have created.
My problem is that sometimes 16 appears in other part of the line. I'm only interested to... (14 Replies)
If I have a set of strings,
C21
F231
H42
1C10
1F113
and I want to isolate the ints following the char, what would the sed string be to find numbers after letters?
If I do,
*, I will get numbers after letters, but I am looking to do something like,
sed 's/*/\t*/g'
this will give me... (14 Replies)
Hi All
I do have a file like this with 6 columns. Groups of data merge together and the group number is indicated above each group.
1
1 12 26 289 3.2e-027 GCGTATGGCGGC
2 12 26 215 6.7e+006 TTCCACCTTTTG
3 9 26 175 ... (1 Reply)
I have a file in the following format. Groups of data merge together and the group number is indicated above each group.
1
adrf
dfgr
dfg
2
dfgr
dfgr
3
dfef
dfr
fd
4
fgrt
fgr
fgg
5
fgrt
fgr (3 Replies)
Hi All,
I'm trying to extract some floating point numbers from within some HTML code like this:
<TR><TD class='awrc'>Parse CPU to Parse Elapsd %:</TD><TD ALIGN='right' class='awrc'> 64.50</TD><TD class='awrc'>% Non-Parse CPU:</TD><TD ALIGN='right' class='awrc'> ... (2 Replies)
Hello all I am a unix newbie....
I have a sun netra t1 and it is freaking out
I am connected to it through a console port, and it is just spitting out a ton on numbers and letters like below its just keeps going and going.
I have tried rebooting it and I cannot get it back to any kind of a... (1 Reply)
How do I check if a variable consisted of letters, numbers or both letters and numbers?
For example, I have a variable $X and I want to print "1" if it contains only letters, "2" if it contains only numbers and "3" if it contains both (2 Replies)