Linux USB CDC sending unexpected characters - linux

I have a USB device which enumerates correctly as a CDC interface. /dev/ttyACM1 is created, and I can ultimately communicate over the endpoints.
But alas, in the first few seconds after enumeration, Some Mysterious Thing on the Linux host side sends AT<CR>AT<CR>AT<CR> to the device, then a few seconds after that, the strange sequence 0x7E 0x00 0x78 0xF0 0x7E. The first is evidently Some Mysterious Thing trying to wake up a modem. The second is presumably similar in intent.
Does anyone know where these unsolicited bytes come from?
I've tried two different VIDs --- 0x1CBE, as the device is a TI chip and that's their default, and 0xF055, in case the TI VID was triggering some alternate driver. Same behavior. The device descriptor looks pretty completely vanilla: CDC class, subclass 0, protocol 0, one configuration.
The host is Ubuntu 14.04.1 LTS, 64-bit. /sys/bus/usb/drivers/ says that it is using the cdc_acm driver. Following is the output from usbmon; the mysterious extra bytes are at the end.
Note that in this run, it was enumerating with USB_CDC_ACM_PROTO_AT_V25TER; I also tried USB_CDC_PROTO_NONE but the result was the same.
ffff8801466ff180 3244792454 S Ci:2:029:0 s 80 06 0100 0000 0012 18 <
ffff8801466ff180 3244792654 C Ci:2:029:0 0 18 = 12011001 02000040 55f00200 00010102 0301
ffff8801466ff180 3244792709 S Ci:2:029:0 s 80 06 0200 0000 0009 9 <
ffff8801466ff180 3244792934 C Ci:2:029:0 0 9 = 09024300 020105c0 00
ffff8801466ff180 3244792997 S Ci:2:029:0 s 80 06 0200 0000 0043 67 <
ffff8801466ff180 3244793306 C Ci:2:029:0 0 67 = 09024300 020105c0 00090400 00010202 01040524 00100104 24020605 24060001
ffff8801466ff180 3244793377 S Ci:2:029:0 s 80 06 0300 0000 00ff 255 <
ffff8801466ff180 3244793570 C Ci:2:029:0 0 4 = 04030904
ffff8801466ff180 3244793632 S Ci:2:029:0 s 80 06 0302 0409 00ff 255 <
ffff8801466ff180 3244793802 C Ci:2:029:0 0 30 = 1e035300 61007400 50006100 71003a00 20007300 65007200 69006100 6c00
ffff8801466ff180 3244793861 S Ci:2:029:0 s 80 06 0301 0409 00ff 255 <
ffff8801466ff180 3244794065 C Ci:2:029:0 0 28 = 1c034800 69006700 68006500 72002000 47007200 6f007500 6e006400
ffff8801466ff180 3244794131 S Ci:2:029:0 s 80 06 0303 0409 00ff 255 <
ffff8801466ff180 3244794309 C Ci:2:029:0 0 18 = 12033100 32003300 34003500 36003700 3800
ffff8801466ff000 3244794739 S Co:2:029:0 s 00 09 0001 0000 0000 0
ffff8801466ff000 3244794897 C Co:2:029:0 0 0
ffff8801466ff000 3244794959 S Ci:2:029:0 s 80 06 0305 0409 00ff 255 <
ffff8801466ff000 3244795140 C Ci:2:029:0 0 54 = 36035300 65006c00 66002000 50006f00 77006500 72006500 64002000 43006f00
ffff8801466ffe40 3244795245 S Ci:2:029:0 s 80 06 0304 0409 00ff 255 <
ffff8801466ffe40 3244795390 C Ci:2:029:0 0 44 = 2c034100 43004d00 20004300 6f006e00 74007200 6f006c00 20004900 6e007400
ffff8801466d1f00 3244796605 S Co:2:029:0 s 21 22 0000 0000 0000 0
ffff8801466d1f00 3244796764 C Co:2:029:0 0 0
ffff8801466d1f00 3244796791 S Co:2:029:0 s 21 20 0000 0000 0007 7 = 80250000 000008
ffff8801466d1f00 3244796931 C Co:2:029:0 0 7 >
ffff8801466ffe40 3244812303 S Ii:2:029:1 -115:1 16 <
ffff8801477a69c0 3244812323 S Co:2:029:0 s 21 22 0003 0000 0000 0
ffff8801477a69c0 3244812387 C Co:2:029:0 0 0
ffff8801466ff480 3244812454 S Bi:2:029:2 -115 128 <
ffff8801466ff600 3244812457 S Bi:2:029:2 -115 128 <
ffff8801466ff6c0 3244812458 S Bi:2:029:2 -115 128 <
ffff8801466ff780 3244812459 S Bi:2:029:2 -115 128 <
ffff8801466ff840 3244812460 S Bi:2:029:2 -115 128 <
ffff8801466ff900 3244812460 S Bi:2:029:2 -115 128 <
ffff8801466fff00 3244812461 S Bi:2:029:2 -115 128 <
ffff8801466ff9c0 3244812462 S Bi:2:029:2 -115 128 <
ffff8801466ffa80 3244812463 S Bi:2:029:2 -115 128 <
ffff8801466ffd80 3244812463 S Bi:2:029:2 -115 128 <
ffff8800971e8240 3244812464 S Bi:2:029:2 -115 128 <
ffff8801473c2f00 3244812465 S Bi:2:029:2 -115 128 <
ffff8801473c2e40 3244812465 S Bi:2:029:2 -115 128 <
ffff8801473c2d80 3244812466 S Bi:2:029:2 -115 128 <
ffff8801473c2cc0 3244812467 S Bi:2:029:2 -115 128 <
ffff8801473c2c00 3244812468 S Bi:2:029:2 -115 128 <
ffff8801477a6300 3244812483 S Co:2:029:0 s 21 20 0000 0000 0007 7 = 00e10000 000008
ffff8801477a6300 3244812634 C Co:2:029:0 0 7 >
ffff8801477a6300 3244813414 S Co:2:029:0 s 21 22 0002 0000 0000 0
ffff8801477a6300 3244813510 C Co:2:029:0 0 0
ffff8801473b96c0 3244913682 S Co:2:029:0 s 21 22 0003 0000 0000 0
ffff8801473b96c0 3244913763 C Co:2:029:0 0 0
ffff8801473c2b40 3244913835 S Bo:2:029:1 -115 1 = 41
ffff8801473c2b40 3244913882 C Bo:2:029:1 0 1 >
ffff8801473c2b40 3245014062 S Bo:2:029:1 -115 1 = 54
ffff8801473c2b40 3245014160 C Bo:2:029:1 0 1 >
ffff8801473c2b40 3245114308 S Bo:2:029:1 -115 1 = 0d
ffff8801473c2b40 3245114394 C Bo:2:029:1 0 1 >
ffff8801473b9480 3245302014 S Co:2:029:0 s 21 20 0000 0000 0007 7 = 00c20100 000008
ffff8801473b9480 3245302184 C Co:2:029:0 0 7 >
ffff8801473c2b40 3248486129 S Bo:2:029:1 -115 1 = 41
ffff8801473c2b40 3248486239 C Bo:2:029:1 0 1 >
ffff8801473c2b40 3248586369 S Bo:2:029:1 -115 1 = 54
ffff8801473c2b40 3248586488 C Bo:2:029:1 0 1 >
ffff8801473c2b40 3248686655 S Bo:2:029:1 -115 1 = 0d
ffff8801473c2b40 3248686737 C Bo:2:029:1 0 1 >
ffff8801473c2b40 3251487738 S Bo:2:029:1 -115 1 = 41
ffff8801473c2b40 3251487836 C Bo:2:029:1 0 1 >
ffff8801473c2b40 3251587976 S Bo:2:029:1 -115 1 = 54
ffff8801473c2b40 3251588088 C Bo:2:029:1 0 1 >
ffff8801473c2b40 3251688249 S Bo:2:029:1 -115 1 = 0d
ffff8801473c2b40 3251688357 C Bo:2:029:1 0 1 >
ffff8801473c2b40 3254489075 S Bo:2:029:1 -115 5 = 7e0078f0 7e
ffff8801473c2b40 3254489188 C Bo:2:029:1 0 5 >
ffff8801473c2b40 3257488394 S Bo:2:029:1 -115 5 = 7e0078f0 7e
ffff8801473c2b40 3257488549 C Bo:2:029:1 0 5 >

Those AT commands are being sent by ModemManager.
It is possible to add a udev rule to tell ModemManager to leave your device alone if it is a problem. Just add a file in /etc/udev/rules.d with a name like foo.rules with content like this:
ATTRS{idVendor}=="12ba", ATTRS{idProduct}=="23ef", ENV{ID_MM_DEVICE_IGNORE}="1"

Related

Find Optimal solution to a function

I have the following Dataframe called df_cam_cb_days:
3m 6m 9m 1y 18m 24m Effective
2021-03-30 49 49 49 49 49 49 2021-03-31
2021-05-13 40 44 44 44 44 44 2021-05-14
2021-06-08 0 26 26 26 26 26 2021-06-09
2021-07-14 0 36 36 36 36 36 2021-07-15
2021-08-31 0 26 48 48 48 48 2021-09-01
2021-10-13 0 0 43 43 43 43 2021-10-14
2021-12-14 0 0 27 62 62 62 2021-12-15
2022-01-26 0 0 0 43 43 43 2022-01-27
2022-03-30 0 0 0 14 63 63 2022-03-31
2022-05-11 0 0 0 0 42 42 2022-05-12
2022-06-08 0 0 0 0 28 28 2022-06-09
2022-07-13 0 0 0 0 35 35 2022-07-14
2022-08-31 0 0 0 0 27 49 2022-09-01
2022-10-12 0 0 0 0 0 42 2022-10-13
2022-12-14 0 0 0 0 0 63 2022-12-15
2023-01-25 0 0 0 0 0 42 2023-01-26
2023-02-10 0 0 0 0 0 15 2023-02-11
and I have the following function that receives the DataFrame and an array:
mon_policy =np.array([.5,
.75,
.75,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1])
#returns numpy array with Breakeven info
def cam_be_mon(mp,df):
columns = ['3m','6m','9m','1y','18m','24m']
days_array = np.array([0,0,0,0,0,0])
days_array = df_cam_cb_days[columns].sum(axis=0).values
data_array= df_cam_cb_days[columns].values.T
c= np.log(mp/36000+1)
be = np.dot(data_array,c)
be = (np.exp(be[0:])-1)*36000/days_array
return be
target = np.array([.3525,.415,.475,.56,.715,.916366])
cam_be_mon(mon_policy,df_cam_cb_days)
The Function as is returns the solution: array([0.61281788, 0.76943154, 0.84886388, 0.88890188,
0.92955637, 0.95151633])
I need to find the set of <mon_policy> that returns a solution = to target , or the closest if there is no solution.
I found the answer with scipy.optimize

Convert Glyph path to SVG

I have the following glyph path:
<glyph glyph-name="right-nav-workflow" unicode="" d="M251 101c0 65 0 131 0 196 26 0 52 0 78 0 0 27 0 54 0 81-29 7-52 23-67 50-11 20-14 41-10 64 8 45 48 79 92 81 49 1 88-29 102-79 2 0 4 0 6 0 20 0 40 0 60 0 5 0 8 1 11 5 32 32 64 64 96 96 2 1 3 3 4 4 42-42 84-84 127-127-1 0-2-2-4-4-32-32-65-65-98-98-2-2-4-6-4-10 0-21 0-43 0-64 30-8 53-24 67-52 12-21 15-44 9-68-11-46-55-78-102-75-48 3-88 42-92 91-4 48 28 91 78 104 0 1 1 3 1 4 0 21 0 42 0 62 0 3-2 5-3 7-28 28-55 55-83 83-1 1-3 3-5 3-22 0-45 0-68 0-5-19-13-36-27-50-14-14-31-23-50-27 0-27 0-53 0-81 26 0 52 0 78 0 0-65 0-130 0-196-65 0-131 0-196 0z m157 156c-40 0-79 0-118 0 0-39 0-78 0-117 40 0 79 0 118 0 0 39 0 78 0 117z m275-58c0 33-26 59-59 59-32 0-59-26-59-59 0-33 27-59 60-59 32 0 58 26 58 59z m-334 216c33 0 59 27 59 59 0 33-26 59-59 59-33 0-59-26-59-59 0-33 26-59 59-59z m275-11c23 23 46 46 69 69-23 23-47 46-69 68-23-22-46-46-69-69 23-22 46-45 69-68z" horiz-adv-x="1000" />
How can I convert this into SVG? I tried to save it in a text file with svg extension but seems is not working.
Take the raw drawing data, put it in a path element, remove the glyph specific attributes, add an appropriate viewBox. Now you have something that works as an inline SVG. If you want to save it as a standalone SVG, then you need to add a name space declaration.
<svg height="400px" width="400px" viewBox="0 0 1000 1000">
<path transform="scale(1,-1) translate(0,-650)" fill="none" stroke="red" stroke-width="1" d="M251 101c0 65 0 131 0 196 26 0 52 0 78 0 0 27 0 54 0 81-29 7-52 23-67 50-11 20-14 41-10 64 8 45 48 79 92 81 49 1 88-29 102-79 2 0 4 0 6 0 20 0 40 0 60 0 5 0 8 1 11 5 32 32 64 64 96 96 2 1 3 3 4 4 42-42 84-84 127-127-1 0-2-2-4-4-32-32-65-65-98-98-2-2-4-6-4-10 0-21 0-43 0-64 30-8 53-24 67-52 12-21 15-44 9-68-11-46-55-78-102-75-48 3-88 42-92 91-4 48 28 91 78 104 0 1 1 3 1 4 0 21 0 42 0 62 0 3-2 5-3 7-28 28-55 55-83 83-1 1-3 3-5 3-22 0-45 0-68 0-5-19-13-36-27-50-14-14-31-23-50-27 0-27 0-53 0-81 26 0 52 0 78 0 0-65 0-130 0-196-65 0-131 0-196 0z m157 156c-40 0-79 0-118 0 0-39 0-78 0-117 40 0 79 0 118 0 0 39 0 78 0 117z m275-58c0 33-26 59-59 59-32 0-59-26-59-59 0-33 27-59 60-59 32 0 58 26 58 59z m-334 216c33 0 59 27 59 59 0 33-26 59-59 59-33 0-59-26-59-59 0-33 26-59 59-59z m275-11c23 23 46 46 69 69-23 23-47 46-69 68-23-22-46-46-69-69 23-22 46-45 69-68z"/>
</svg>
Update - Robert points out that the SVG Fonts spec has a y axis (0 on the bottom) that's inverted from the SVG norm (0 is the top) -> so you also need to flip the drawing along the x axis by using a scale (1,-1).

Find duplicate content and consolidate in groovy

I want to edit a file automatically with groovy.
For example, i have the following textfile:
(First line is only for your understanding)
branch ID item ID - - weight piece --- --- ---
178568305 108350 0 0 0 -1 215 215 012
178568305 102190 0 0 0 -1 74 74 012
178568305 102120 0 0 0 -8 35 35 012
178568305 102190 0 0 0 -6 74 74 012
178568305 102190 0 0 0 -6 74 74 012
178587626 108280 0 0 0 -3 189 189 012
178587626 159550 0 0 0 -1 499 499 012
178587626 107740 0 0 0 -4 229 229 012
178587626 105330 0 0 -10 0 626 626 012
178587626 102190 0 0 0 -6 74 74 012
In column 1 i have a brach ID
In column 2 i have a item ID
In column 5 i have a weight, for example in gram
In column 6 i have a number of pieces
Column 3, 4, 7, 8 and 9 are not important
In branch ID:
From line 1 to 5 and 6 and from 6 to 10 i have two different branchs IDs
In item ID:
In line 2, 4 and 5 i have the same item ID always to the same branche ID.
Now, what i want is to consolidate the the item ID 102190 with branch ID 178568305 to one line.
But the piece or weight have to count in sum in these one line.
But attention: In Line 10 i have the same item ID like in Line 2 or 4, but i have a another branch ID. It is not allowed to consolidate the weight/piece from line 10 with 2, 4 and 5!
For Example:
branch ID item ID - - weight piece --- --- ---
178568305 108350 0 0 0 -1 215 215 012
178568305 102120 0 0 0 -8 35 35 012
178568305 102190 0 0 0 -13 74 74 012
178587626 108280 0 0 0 -3 189 189 012
178587626 159550 0 0 0 -1 499 499 012
178587626 107740 0 0 0 -4 229 229 012
178587626 105330 0 0 -10 0 626 626 012
178587626 102190 0 0 0 -6 74 74 012
My input text file is only separated with spaces. My output textfile must be exact the same.
Unfortunately, I have no idea how to create this in a groovy script.
Can anyone help? Tutorials are helpful too. I have no idea for the logical script expiration.
You just need to group the data by branchId and itemId, here is a working code for you:
def input = new File("input.txt")
def output = new File("output.txt")
PrintWriter printWriter = new PrintWriter(output)
Map<String, String[]> result = [:]
input.eachLine { currentLine, lineNumber ->
def array = currentLine.split(" +");
String rowId = array[0] + "_" + array[1];
if(lineNumber == 1 ){
result.put(rowId, array)
}else {
String[] rowValues = array;
if(null != result.get(rowId)){
String[] existingValues = result.get(rowId);
for(int i = 0; i < existingValues.length; ++i){
try{
existingValues[i] = String.valueOf( rowValues[i].toInteger() + existingValues[i].toInteger())
}catch (NumberFormatException ex){
print(ex)
}
}
}else{
result.put(rowId, rowValues)
}
println(array)
}
}
int maxColumnWidth = 14;
result.each { key, value ->
for(int i = 0; i < value.length; ++i){
if(i == 0){
printWriter.print(value[i])
}else{
String v = value[i];
while(v.length() < maxColumnWidth){
v = " " + v;
}
printWriter.print(v)
}
}
printWriter.println()
}
printWriter.close()
Sample Input:
branch ID item ID - - weight piece --- --- ---
178568305 108350 0 0 0 -1 215 215 012
178568305 102190 0 0 0 -1 74 74 012
178568305 102120 0 0 0 -8 35 35 012
178568305 102190 0 0 0 -6 74 74 012
178568305 102190 0 0 0 -6 74 74 012
178587626 108280 0 0 0 -3 189 189 012
178587626 159550 0 0 0 -1 499 499 012
178587626 107740 0 0 0 -4 229 229 012
178587626 105330 0 0 -10 0 626 626 012
178587626 102190 0 0 0 -6 74 74 012
Output:
branch ID item ID - - weight piece --- --- ---
178568305 108350 0 0 0 -1 215 215 012
535704915 306570 0 0 0 -13 222 222 36
178568305 102120 0 0 0 -8 35 35 012
178587626 108280 0 0 0 -3 189 189 012
178587626 159550 0 0 0 -1 499 499 012
178587626 107740 0 0 0 -4 229 229 012
178587626 105330 0 0 -10 0 626 626 012
178587626 102190 0 0 0 -6 74 74 012

Grep rows with a length of 3

Hi i have a table which looks like this:
chr10 84890986 84891021 2 17.5 2 93 0 61 48 2 48 0 1.16 GA
chr10 84897562 84897613 2 25.5 2 100 0 102 50 49 0 0 1 AC
chr10 84899819 84899844 2 12.5 2 100 0 50 0 0 52 48 1 GT
chr10 84905282 84905318 6 5.8 6 87 6 54 80 19 0 0 0.71 AAAAAC
chr10 84955235 84955267 2 16 2 100 0 64 50 0 0 50 1 AT
chr10 84972254 84972288 2 17 2 93 0 59 2 0 47 50 1.16 GT
chr10 85011399 85011478 3 25.7 3 80 12 63 58 1 40 0 1.06 GAA
chr10 85011461 85011525 3 20.7 3 87 6 74 39 0 60 0 0.97 GAG
chr10 85014721 85014841 5 23.8 5 78 8 66 0 69 0 29 1 TTCCC
chr10 85021530 85021701 5 38.4 5 84 13 53 74 0 24 0 0.85 AAGAG
chr10 85045413 85045440 3 9 3 100 0 54 66 33 0 0 0.92 CAA
chr10 85059334 85059364 5 6 5 92 0 51 20 3 0 76 0.92 ATTTT
chr10 85072010 85072038 2 14 2 100 0 56 50 50 0 0 1 CA
chr10 85072037 85072077 4 10 4 84 10 55 25 22 0 52 1.47 ATCT
chr10 85084308 85084338 6 5 6 91 0 51 83 13 3 0 0.77 CAAAAA
chr10 85096597 85096640 3 14.7 3 95 4 79 69 30 0 0 0.88 AAC
chr10 85151154 85151190 6 6.5 6 87 12 51 0 11 0 88 0.5 TTTCTT
chr10 85168255 85168320 4 16.2 4 100 0 130 50 0 49 0 1 AGGA
chr10 85173155 85173184 2 14.5 2 100 0 58 48 0 0 51 1 TA
chr10 85196836 85196861 2 12.5 2 100 0 50 52 48 0 0 1 AC
chr10 85215511 85215546 2 17.5 2 100 0 70 51 48 0 0 1 AC
chr10 85225048 85225075 2 13.5 2 100 0 54 51 48 0 0 1 AC
chr10 85242322 85242357 2 17.5 2 93 0 61 0 2 48 48 1.16 TG
chr10 85245934 85245981 4 11 4 79 20 51 27 2 0 70 0.99 ATTT
chr10 85249139 85249230 5 18.8 5 88 6 116 0 60 0 39 0.97 TTCCC
chr10 85251100 85251153 5 11 5 97 2 92 0 0 37 62 0.96 GTTTG
chr10 85268725 85268752 4 6.8 4 100 0 54 0 25 0 74 0.83 CTTT
chr10 85268767 85268798 4 7.8 4 100 0 62 0 0 22 77 0.77 TTTG
chr10 85269189 85269239 6 8.8 6 79 16 54 84 2 12 2 0.8 AAAAGA
chr10 85330217 85330253 2 18 2 100 0 72 0 0 50 50 1 TG
chr10 85332256 85332314 4 15 4 82 7 75 70 1 27 0 0.97 AAGA
chr10 85337969 85337996 2 13.5 2 100 0 54 0 0 48 51 1 TG
chr10 85344795 85344957 2 75.5 2 83 12 198 45 4 3 45 1.42 TA
chr10 85349732 85349765 5 6.8 5 93 6 59 84 15 0 0 0.61 AAAAC
chr10 85353082 85353109 5 5.4 5 100 0 54 0 22 18 59 1.38 CTGTT
I want to extract all rows with have 3 and only 3 characters in the last column. My try till now is this:
grep -E "['ACTG']['ACTG']['ACTG']{1,3}$"
But this gives me everything from 3 and longer than 3. I tried many different combinations but nothing seems to give me what i want. Any ideas?
If you like to try awk, you can do:
awk '$NF~/\<...\>/' file
chr10 85011399 85011478 3 25.7 3 80 12 63 58 1 40 0 1.06 GAA
chr10 85011461 85011525 3 20.7 3 87 6 74 39 0 60 0 0.97 GAG
chr10 85045413 85045440 3 9 3 100 0 54 66 33 0 0 0.92 CAA
chr10 85096597 85096640 3 14.7 3 95 4 79 69 30 0 0 0.88 AAC
It will test if last field $NF has 3 character ...
This regex would also do: awk '$NF~/^...$/'
Or if you need exact characters. (PS this needs awk 4.x, or use of switch --re-interval)
awk '$NF~/^[ACTG]{3}$/' file
Using grep
grep -E " [ACTG]{3}$" file
chr10 85011399 85011478 3 25.7 3 80 12 63 58 1 40 0 1.06 GAA
chr10 85011461 85011525 3 20.7 3 87 6 74 39 0 60 0 0.97 GAG
chr10 85045413 85045440 3 9 3 100 0 54 66 33 0 0 0.92 CAA
chr10 85096597 85096640 3 14.7 3 95 4 79 69 30 0 0 0.88 AAC
You need the space, to separate last column, and {3} to get 3 and only 3 characters.
If you want to print the rows which has exactly three chars in the last column then you could use the below grep command.
grep -E " [ACTG]{3}$"
[ACTG]{3} Matches exactly three characters from the given list.
You have to grep either " ['ACTG']['ACTG']['ACTG']$" or " ['ACTG']{1,3}$".
Currently, you are grepping 3 to 5 'ACTG'.
Also, the quotes are unnecessary ['ACTG'] means "match anything between []" so any of the 5 characters 'ACTG, just grep " [ACTG]{1,3}$".
Be sure to use a delimiter for the left part (space ' ', tab\t if it is tab delimited, word boundary \b or \W).
If your lines are all ending with [ACTG]+, you can even only grep -E "\W.{,3}$"
Another way that you could do this would be using awk:
$ awk '$NF ~ /^[ACTG][ACTG][ACTG]$/' file
chr10 85011399 85011478 3 25.7 3 80 12 63 58 1 40 0 1.06 GAA
chr10 85011461 85011525 3 20.7 3 87 6 74 39 0 60 0 0.97 GAG
chr10 85045413 85045440 3 9 3 100 0 54 66 33 0 0 0.92 CAA
chr10 85096597 85096640 3 14.7 3 95 4 79 69 30 0 0 0.88 AAC
This prints all lines whose last field exactly matches 3 of the characters "A", "C", "T" or "G".
2 hours late but this is one way in awk
This can be easily edited for different lengths and fields.
awk 'length($NF)==3' file
As i was looking for answers myself i found out that Perl regex work more efficiently:
this does the deal : grep -P '\t...$' Way more compact code.
$ cat roi_new.bed | grep -P "\t...$"
chr10 81038152 81038182 3 9.7 3 92 7 51 30 0 0 70 0.88 TTA
chr10 81272294 81272320 3 8.7 3 100 0 52 0 30 69 0 0.89 GGC
chr10 81287690 81287720 3 10 3 100 0 60 66 33 0 0 0.92 CAA

Benchmarking CPU and File IO for an application running on Linux

I wrote two programs to run on Linux, each using a different algorithm, and I want to find a way (preferably using a benchmarking software) to compare the CPU usage and IO operations between these two programs.
Is there such a thing? and if yes, where can I find them. Thanks.
You can try hardinfo
Or there are like n different tools measuring system performance if measuring it while running your app solves your purpose
And you can also check this thread
You might try vmstat command:
vmstat 2 20 > vmstat.txt
20 samples of 2 seconds
bi = KB in, bo = KB out with wa = waiting for I/O
I/O can also increase cache demands
%CPU utilisation = us (user) = sy (system)
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
0 0 0 277504 17060 82732 0 0 91 87 1432 236 11 3 84 1
0 0 0 277372 17068 82732 0 0 0 24 1361 399 23 8 59 10
test start
0 1 0 275240 17068 82732 0 0 0 512 1342 305 24 4 69 4
2 1 0 275232 17068 82780 0 0 24 10752 4176 216 7 8 0 85
1 1 0 275240 17076 82732 0 0 12288 2590 5295 243 15 8 0 77
0 1 0 275240 17076 82748 0 0 8 11264 4329 214 6 12 0 82
0 1 0 275240 17076 82780 0 0 16 11264 4278 233 15 10 0 75
0 1 0 275240 17084 82780 0 0 19456 542 6563 255 10 7 0 83
0 1 0 275108 17084 82748 0 0 5128 3072 3501 265 16 37 0 47
3 1 0 275108 17084 82748 0 0 924 5120 8369 3845 12 33 0 55
0 1 0 275116 17092 82748 0 0 1576 85 11483 6645 5 50 0 45
1 1 0 275116 17092 82748 0 0 0 136 2304 689 3 9 0 88
2 1 0 275084 17100 82732 0 0 0 352 2374 800 14 26 0 61
0 0 0 275076 17100 82732 0 0 546 118 2408 1014 35 17 47 1
0 1 0 275076 17104 82732 0 0 0 62 1324 76 3 2 89 7
1 1 0 275076 17108 82732 0 0 0 452 1879 442 8 13 66 12
0 0 0 275116 17108 82732 0 0 800 352 2456 1195 19 17 56 8
0 1 0 275116 17112 82732 0 0 0 54 1325 76 4 1 88 8
test end
1 1 0 275116 17116 82732 0 0 0 510 1717 286 6 10 72 11
1 0 0 275076 17116 82732 0 0 1600 1152 3087 1344 23 29 41 7

Resources