Is there an available list for DISTRO_FEATURES_append?
for example:
DISTRO_FEATURES_append = " systemd"
This is the only one I have known but I want to know is any else I can choose.
Another question, can we add *.bb directly into DISTRO_FEATURES_append?
ex:
DISTRO_FEATURES_append = " dmidecode"
bitbake IMAGE_NAME -e | grep DISTRO_FEATURES=
Related
I have a file containing multiple tests with detailed action written one beneath another. All test blocks are separated one from another by new line. I want to extract only first and last line from the all blocks and put it on one line for each block into a new file. Here is an example:
input.txt:
[test1]
duration
summary
code=
Results= PASS
[test2]
duration
summary=x
code=
Results=FAIL
.....
[testX]
duration
summary=x
code=
Results= PASS
output.txt should be sometime like this:
test1 PASS
test2 FAIL
...
testX PASS
eg2:
[Linux_MP3Enc_xffv.2_Con_37_003]
type = testcase
summary = MP3 encoder test
ActionGroup[Linux_Enc] = PASS
ActionGroup[Linux_Playb] = PASS
ActionGroup[Linux_Pause_Resume] = PASS
ActionGroup[Linux_Fast_Seek] = PASS
Duration = 230.607398987 s
Total_Result = PASS
[Composer__vtx_007]
type = testcase
summary = composer
Background[0xff000000] = PASS
Background[0xffFFFFFF] = PASS
Background[0xffFF0000] = PASS
Background[0xff00FF00] = PASS
Background[0xff0000FF] = PASS
Background[0xff00FFFF] = PASS
Background[0xffFFFF00] = PASS
Background[0xffFF00FF] = PASS
Duration = 28.3567230701 s
Total_Result = PASS
[Videox_Rotate_008]
type = testcase
summary = rotation
Rotation[0] = PASS
Rotation[1] = PASS
Rotation[2] = PASS
Rotation[3] = PASS
Duration = 14.0116529465 s
Total_Result = PASS
Thank you!
Short and simple gnu awk:
awk -F= -v RS='' '{print $1 $NF}' file
[Linux_MP3Enc_xffv.2_Con_37_003] PASS
[Composer__vtx_007] PASS
[Videox_Rotate_008] PASS
If you do not like the brackets:
awk -F'[]=[]' -v RS='' '{print $2 $NF}' file
Linux_MP3Enc_xffv.2_Con_37_003 PASS
Composer__vtx_007 PASS
Videox_Rotate_008 PASS
Using sed as tagged (although other tools would probably be more natural to use) :
sed -nE '/^\[.*\]$/h;s/^Results= ?//;t r;b;:r;H;x;s/\n/ /;p'
Explanation :
/^\[.*\]$/h # matches the [...] lines, put them in the hold buffer
s/^Results= ?// # matches the Results= lines, discards the useless part
t r;b # on lines which matched, jump to label r;
# otherwise jump to the end (and start processing the next line)
:r;H;x;s/\n/ /;p # label r; append the pattern space (which contains the end of the Results= line)
# to the hold buffer. Switch Hold buffer and pattern space,
# replace the linefeed in the pattern space by a space and print it
You can try it here.
One way to solve this is using a regular expression such as:
(?<testId>test\d+)(?:.*\n){4}.*(?<outcome>PASS|FAIL)
The regex matches your sample output and stores the test id (e.g. "test1") in the capture group named "testId" and the outcome (e.g. "PASS") in the capture group "outcome".
(Test it in regexr)
The regex can be used in any language with regex support. The below code shows how to do it in Python.
(Test it in repl.it)
import re
# Read from input.txt
with open('input.txt', 'r') as f:
indata = f.read()
# Modify the regex slightly to fit Python regex syntax
pattern = '(?:.*)(?P<testId>test\d+)(?:.*\n){4}.*(?P<outcome>PASS|FAIL)'
# Get a generator which yeilds all matches
matches = re.finditer(pattern, indata)
# Combine the matches to a list of strings
outputs = ['{} {}'.format(m.group('testId'), m.group('outcome')) for m in matches]
# Join all rows to one string
output = '\n'.join(outputs)
# Write to output.txt
with open('output.txt', 'w') as f:
f.write(output)
Running the above script on input.txt containing:
[test1]
duration
summary
code=
Results= PASS
[test2]
duration
summary=x
code=
Results=FAIL
[test444]
duration
summary=x
code=
Results= PASS
yields a file output.txt containing:
test1 PASS
test2 FAIL
test444 PASS
In order to print the first and last line from the block, how about:
awk -v RS="" '{
n = split($0, a, /\n/)
print a[1]
print a[n]
}' input.txt
Result for the 1st example:
[Linux_MP3Enc_xffv.2_Con_37_003]
Total_Result = PASS
[Composer__vtx_007]
Total_Result = PASS
[Videox_Rotate_008]
Total_Result = PASS
The man page of awk tells:
If RS is set to the null string, then records are separated by blank lines.
You can easily split the block with blank lines with this feature.
Hope this helps.
Suppose I have a char variable in Matlab like this:
x = 'hello my name $ is Sean $ Daley.';
I want to replace the first '$' with the symbol '&', and the second '$' with the symbol '#'.
Furthermore, if I have a more complicated char such that pairs of '$' repeat many times, I want to repeat the same pattern. So the following:
y = 'hello $ my $ name is $ Sean $ Daley $.$.';
would be transformed into:
'hello & my # name is & Sean # Daley &.#.'
I have tried coding this manually via for loops and while loops, but the code is just so ugly. Are there any simple functions that I can use?
Since you're dealing with single characters and non-nested pairs of flags, you can easily do this with a simple call to find and some indexed replacement:
y = 'hello $ my $ name is $ Sean $ Daley $.$.';
index = find(y == '$');
y(index(1:2:end)) = '&';
y(index(2:2:end)) = '#';
And the result:
y =
'hello & my # name is & Sean # Daley &.#.'
I'm trying to use sed to replace a specific line within a configuration file:
The pattern for the line I want to replace is:
ALLOWED_HOSTS.*
The text I want to insert is:
'$PublicIP' (Including the single ticks)
But when I run the command:
sed 's/ALLOWED_HOSTS.*/ALLOWED_HOSTS = ['$PublicIP']/g' /root/project/django/mysite/mysite/settings.py
The line is changed to:
ALLOWED_HOSTS = [1.1.1.1]
instead of:
ALLOWED_HOSTS = ['1.1.1.1']
How shall I edit the command to include the single ticks as well?
You could try to escape the single ticks , or better you can reassign the variable including the simple ticks:
PublicIP="'$PublicIP'".
By the way even this sed without redifining var, works ok in my case:
$ a="3.3.3.3"
$ echo "ALLOWED_HOSTS = [2.2.2.2]" |sed 's/2.2.2.2/'"'$a'"'/g'
ALLOWED_HOSTS = ['3.3.3.3']
Even this works ok:
$ echo "ALLOWED_HOSTS = [2.2.2.2]" |sed "s/2.2.2.2/'$a'/g"
ALLOWED_HOSTS = ['3.3.3.3']
I try to figure it out how can grep in linux only the "SIG:" hash part from that log below:
20120927:10:57:23|89252871|3342|ESP individual score details for Message ID: <esp:msgid> -|<RBL:<0> SHA:<0> SHA_FLAGS:<0> UHA:<12> ISC:<0> BAYES:<0> SenderID:<0> DKIM:<0> TS:<-1> SIG:<309875857436-4372-986476-327698-7436-984376-43276-98437643-8276-84327-6743-6874-986-86743-86732-867432-687432-687> DSC:<0> ('TRU_spam1', 47):<0> ('TRU_legal_spam', 31):<0> ('TRU_marketing_spam', 34):<0> ('TRU_profanity_spam', 39):<0> ('TRU_medical_spam', 35):<0> ('TRU_playsites', 46):<0> ('TRU_money_spam', 37):<0> ('TRU_stock_spam', 41):<0> ('TRU_embedded_image_spam', 27):<0> ('TRU_urllinks', 49):<0> ('TRU_watch_spam', 42):<0> ('TRU_phish_spam', 38):<0> ('TRU_spam2', 48):<0> ('TRU_misc_spam', 36):<0> ('TRU_LOREAL', 55):<0> ('TRU_freehosting', 45):<0> ('TRU_lotto_spam', 32):<0> ('TRU_ru_spamsubj', 56):<0> ('TRU_adult_spam', 18):<0> ('URL Real-Time Signatures', 9):<0> ('TRU_scam_spam', 40):<0>:89252871>|
Final view:
309875857436-4372-986476-327698-7436-984376-43276-98437643-8276-84327-6743-6874-986-86743-86732-867432-687432-687
With Perl regex (works on GNU grep):
grep -oP '(?<=SIG:<)[^>]*(?=>)'
grep alone cannot help you much here. You can add cut to your toolbox:
grep -o 'SIG:<[^>]\+' | cut -f2 -d\<
First, select SIG and everything following it up to a >. Then, only return what's after the first <.
awk '{for(i=1;i<=NF;i++)if($i~/SIG:/){gsub("SIG:<","",$i);gsub(">","",$i);print $i;break}}' your_file
Use two greps, one to grab the right field, and one clean up:
<infile grep -o 'SIG:<[^>]*' | grep -o '[^<]*$'
sed 's/.*SIG:<\([^>]\+\)>.*/\1/g' INPUTFILE
Might work for you
I have inherited a flat html file with a few hundred lines similar to this:
<blink>
<td class="pagetxt bordercolor="#666666 width="203 colspan="3 height="20>
</blink>
So far I have not been able to work out a sed way of inserting the closing double quotes for each element. Probably needs something other than sed to do this. Can anyone suggest an easy way to do this?
Thanks
sed -i 's/"\([^" >]\+\)\( \|>\)/"\1"\2/g' file.html
Explanation:
" - leading double quote
\([^" >]\+\) - non-quote-or-space-or-'>' chars, grouped (into group 1)
\( \|>\) - terminating space or '>', grouped (into group 2)
We replace it with '"<group1>"<group2>'.
One solution that pops out at me is to parse through each line of the file looking for the quote. When it finds one, activate a flag to keep track of being inside a quoted area, then continue parsing the line until it hits the first space or > it comes to and inserts an additional " just before it. Flip the flag off, then continue through the string looking for the next quote. Probably not a perfect solution, but a start perhaps.
If all lines share the same structure, you could use a simple texteditor to globally replace
' bordercolor'
with
'" bordercolor'
(without single-quotes). This is then independend from the field values and works similarly for the other fields. You still have to do some manual work, but if it's just one big file, I'd bite the bullet this time and not waste probably more time working out a sed-solution.
This should do if your file is simple - it won't work if you have whitespace which should be inside the quotes - in that case, a more complex code will be needed, but can be done along the same lines.
#!usr/bin/env python
#change the "utf-8" bellow to your files encoding
data = open("<myfile.html>").read().decode("utf-8")
new_data = []
inside_tag = False
inside_quotes = False
for char in data:
if char == "<":
inside_tag = True
if char == '"':
inside_quotes = True
if inside_tag and (char.isspace() or char==">") and inside_quotes:
new_data.append('"')
inside_quotes = False
if char == ">":
inside_tag = False
new_data.append(char)
outputfile = open("<mynewfile.html>", "wt")
outputfile.write("".join(new_data).encode("utf-8"))
outputfile.close()
with bash
for file in *
do
flag=0
while read -r line
do
case "$line" in
*"<blink>"*)
flag=1
;;
esac
if [ "$flag" -eq 1 ];then
case "$line" in
*class=\"pagetxt*">" )
line="${line%>}\">"
flag=0
;;
esac
fi
echo "${line}"
done <"file" > temp
mv temp "$file"
done
Regular expressions are your friend:
Find: (="[^" >]+)([ >])
Replace: \1"\2
After you've done that, make sure to run this one too:
Find: </?blink>
Replace: \n
(This won't fix more than one class on an element, like <element class="class1 class2 id="jimmy">)