Difference between obj-m+=[modules_list] and obj-m=[modules_list] - linux

What's a difference between obj-m=md1.o md2.o and obj-m+=md1.o md2.o in a kernel make-file?

You can try to infer it with an example:
obj-m= a.o b.o
obj-m1= 1 2 3
obj-m= c.o d.o
obj-m1+= 4 5 6
ALL :
echo $(obj-m) -- $(obj-m1)
Its output is
c.o d.o -- 1 2 3 4 5 6
So: = assigns (overwriting), and += appends.

Related

Use awk command to get information below a pattern

I have a file with a wide range of information and I want to extract some data from here. I only will post here the interesting part. I want to extract IQ and JQ values as well as the J_ij[meV] value which is two lines above. I read this question How to print 5 consecutive lines after a pattern in file using awk where a pattern is used to extract information bellow and I was thinking doing something similar. My initial idea was:
awk '/IQ =/ { print $6,$12 } /IQ =/ {for(i=2; i<=2; i++){ getline; print $11 }}' input.text > output.txt
Loop appears not to working
IT IQ JT JQ N1 N2 N3 DRX DRY DRZ DR J_ij [mRy] J_ij [meV]
IT = 1 IQ = **1** JT = 1 JQ = **1**
->Q = ( -0.250, 0.722, 0.203) ->Q = ( -0.250, 0.722, 0.203)
1 1 1 1 0 0 0 0.000 0.000 0.000 0.000 0.000000000 **0.000000000**
IT = 1 IQ = **1** JT = 6 JQ = **6**
->Q = ( -0.250, 0.722, 0.203) ->Q = ( 0.000, 1.443, 0.609)
1 1 6 6 -1 0 -1 -0.250 -0.144 -0.406 0.498 0.135692822 **1.846194885**
IT = 1 IQ = **1** JT = 8 JQ = **8**
->Q = ( -0.250, 0.722, 0.203) ->Q = ( 0.000, 0.577, 0.609)
1 1 8 8 0 0 -1 0.250 -0.144 -0.406 0.498 0.017676555 **0.240501782**
My expected output is:
IQ JQ J_ij [meV]
1 1 0.000000000
1 6 1.846194885
1 8 0.240501782
It comes from the bold words (** **), first line is only indicative.
Could you please try following. Written and tested with shown examples.
awk '
BEGIN{
print "IQ JQ J_ij [meV]"
}
FNR>1 && /IQ =/{
value=$6 OFS $12
found=1
next
}
found && NF && !/ ->Q/{
if(value){
print value OFS $NF
}
value=found=""
}' Input_file
Output will be as follows.
IQ JQ J_ij [meV]
1 1 0.000000000
1 6 1.846194885
1 8 0.240501782

how to use the qsub without root login

I borrowed the SGE system, but it doesn't work when I qsub.
#!/bin/bash
#PBS -l nodes=1:ppn=4
#PBS -N pix2pix
#PBS -o pix2pix.out
#PBS -e pix2pix.err
#PBS -q GPU_HIGH
#PBS -l walltime=72000:00:00
#cd $PBS_0_WORKDIR
cd /public/home/chensu/others/Guicai/pix2pix-tensorflow
source activate tensorflow
python /public/home/chensu/others/Guicai/pix2pix-tensorflow/pix2pix.py --mode train --output_dir /public/home/chensu/others/Guicai/pix2pix-tensorflow/face2face-model --max_epochs 2000 --input_dir /public/home/chensu/others/Guicai/pix2pix-tensorflow/photos/combined/train --which_direction AtoB --batch_size 4
there are many free queues.
qstat -q
server: admin1
Queue Memory CPU Time Walltime Node Run Que Lm State
---------------- ------ -------- -------- ---- --- --- -- -----
FAT_HIGH -- -- -- -- 0 0 0 E R
high -- -- -- -- 10 0 10 E R
MIC_HIGH -- -- -- -- 0 0 0 E R
GPU_HIGH -- -- -- -- 0 0 0 E R
low -- -- -- -- 4 0 20 E R
batch -- -- -- -- 0 0 20 E R
middle -- -- -- -- 0 0 10 E R
----- -----
14 0
when I qsub my test.pbs with qsub test.pbs
MGMT1:
Req'd Req'd Elap
Job ID Username Queue Jobname SessID NDS TSK Memory Time S Time
20414.MGMT1 chensu GPU_HIGH pix2pix -- 1 4 -- 72000:00: C --
Also there are no log, so I don't know what happened.
Any suggestions will be appreciated

how to write a bash script for matching files [duplicate]

This question already has answers here:
Inner join on two text files
(5 answers)
Closed 6 years ago.
I would like to write a script to match two files. I have a file which is always change and a file acts as a database.
Input file1:
1
3
5
7
9
Database matched file1:
A B C D E F
1 0.27776079 0.302853938 1.52415756 2.751714059 1.363932416 2.286189771
2 0.332465 0.777918524 0.705056607 0.484138872 0.443787105 0.848742839
3 0.941768856 0.19125 0.573714912 0.5040488 0.526207725 1.554118026
4 1.717348092 0.19642752 0.315945 0.1331712 0.28427498 0.30113875
5 0.802253697 0.3768849 0.426688 0.27693 0.591697038 0.3832675
6 0.2752232 0.570078 0.3847095 0.659548575 0.327469824 0.3346875
7 0.153272 0.36594447 0.19125 0.526602427 0.44771265 0.31136
8 0.637448551 0.735756919 1.284158594 0.464060016 0.259459816 0.887975536
9 0.397221469 0.20808 0.268226 0.710250679 0.493069267 0.47672443
10 0.196928 0.492713856 0.22302 0.783853054 0.303534 1.736908487
11 0.510789888 0.14948712 0.26432 0.684485438 0.683017627 0.614033957
desired output file1:
A B C D E F
1 0.27776079 0.302853938 1.52415756 2.751714059 1.363932416 2.286189771
3 0.941768856 0.19125 0.573714912 0.5040488 0.526207725 1.554118026
5 0.802253697 0.3768849 0.426688 0.27693 0.591697038 0.3832675
7 0.153272 0.36594447 0.19125 0.526602427 0.44771265 0.31136
9 0.397221469 0.20808 0.268226 0.710250679 0.493069267 0.47672443
I would like to extract the matched lines from the database.
head -1 database1.txt > output1.txt
grep -wf inputfile1.txt database1.txt >> output1.txt
head -1 database1.txt > output2.txt
grep -wf inputfile2.txt database1.txt >> output2.txt
head -1 database2.txt > output3.txt
grep -wf inputfile3.txt database2.txt >> output3.txt
I try to use nano command but every time need to change the syntax.
You can use the join command to join the 2 files on 1st column:
$ cat file1
1
3
5
7
9
$ cat file2
A B C D E F
1 0.27776079 0.302853938 1.52415756 2.751714059 1.363932416 2.286189771
2 0.332465 0.777918524 0.705056607 0.484138872 0.443787105 0.848742839
3 0.941768856 0.19125 0.573714912 0.5040488 0.526207725 1.554118026
4 1.717348092 0.19642752 0.315945 0.1331712 0.28427498 0.30113875
5 0.802253697 0.3768849 0.426688 0.27693 0.591697038 0.3832675
6 0.2752232 0.570078 0.3847095 0.659548575 0.327469824 0.3346875
7 0.153272 0.36594447 0.19125 0.526602427 0.44771265 0.31136
8 0.637448551 0.735756919 1.284158594 0.464060016 0.259459816 0.887975536
9 0.397221469 0.20808 0.268226 0.710250679 0.493069267 0.47672443
10 0.196928 0.492713856 0.22302 0.783853054 0.303534 1.736908487
11 0.510789888 0.14948712 0.26432 0.684485438 0.683017627 0.614033957
$ sed -n '1p' file2 && join --nocheck-order file1 <(sed -n '1!p' file2)
A B C D E F
1 0.27776079 0.302853938 1.52415756 2.751714059 1.363932416 2.286189771
3 0.941768856 0.19125 0.573714912 0.5040488 0.526207725 1.554118026
5 0.802253697 0.3768849 0.426688 0.27693 0.591697038 0.3832675
7 0.153272 0.36594447 0.19125 0.526602427 0.44771265 0.31136
9 0.397221469 0.20808 0.268226 0.710250679 0.493069267 0.47672443
$

How to run multiple composed commands (with multiple arguments) in gnu parallel?

I want to run the following scripts with different input arguments using GNU Parallel in parallel:
Rscript svmRScript_v2.copy.r 0.1 1 #(1) 0.1 and 1 are the input arguments
Rscript svmRScript_v2.copy.r 0.1 2 #(2)
Rscript svmRScript_v2.copy.r 0.1 5 #(3)
Rscript svmRScript_v2.copy.r 0.1 10 #(4)
So all I wanna do is run the 'commands' (1),(2),(3),(4) in parallel using GNU parallel.
My best guess was something like
parallel Rscript < svmRScript_v2.copy.r ::: 0.1 1 ::: 0.1 2 ::: 0.1 5 ::: 0.1 10
I know this is entirely wrong and I'm getting the following error:
Fatal error: cannot open file ':::': No such file or directory.
Any suggestion what I need to change?
Thanks in advance.
The obvious is:
parallel Rscript svmRScript_v2.copy.r 0.1 ::: 1 2 5 10
But I have the feeling you might want 0.1 and 0.2 later:
parallel Rscript svmRScript_v2.copy.r ::: 0.1 0.2 ::: 1 2 5 10
If the order of the arguments is wrong:
parallel Rscript svmRScript_v2.copy.r {2} {1} ::: 0.1 0.2 ::: 1 2 5 10
Did you have a chance to watch the intro videos and walk through the tutorial?

How to generate plain-text source-code PDF examples that work in a document viewer?

I just found the post Adobe Forums: Simple Text String Example in specification broken., so I got interested in finding plain-text source code PDF examples.
So, through that post, I eventually found:
The webpage PDF Reference and Adobe Extensions to the PDF Specification | Adobe Developer Connection ; which contains:
The PDF Document Management – Portable Document Format – Part 1: PDF 1.7, First Edition (PDF32000_2008.pdf)
The PDF 1.7 spec has on page 699 appendix "_Annex H (informative) Example PDF files"; and from there, I wanted to try "H.3 Simple Text String Example" (the "classic Hello World").
So I tried to save this as hello.pdf (_except note when you copy from the PDF32000_2008.pdf, you may get "%PDF-1. 4" - that is, a space inserted after 1., which must be removed_) :
%PDF-1.4
1 0 obj
<< /Type /Catalog
/Outlines 2 0 R
/Pages 3 0 R
>>
endobj
2 0 obj
<< /Type /Outlines
/Count 0
>>
endobj
3 0 obj
<< /Type /Pages
/Kids [ 4 0 R ]
/Count 1
>>
endobj
4 0 obj
<< /Type /Page
/Parent 3 0 R
/MediaBox [ 0 0 612 792 ]
/Contents 5 0 R
/Resources << /ProcSet 6 0 R
/Font << /F1 7 0 R >>
>>
>>
endobj
5 0 obj
<< /Length 73 >>
stream
BT
/F1 24 Tf
100 100 Td
( Hello World ) Tj
ET
endstream
endobj
... and I'm trying to open it:
evince hello.pdf
... however, evince cannot open it: "Unable to open document / PDF document is damaged"; and also:
Error: PDF file is damaged - attempting to reconstruct xref table...
Error: Couldn't find trailer dictionary
Error: Couldn't read xref table
I also check with qpdf:
$ qpdf --check hello.pdf
WARNING: hello.pdf: file is damaged
WARNING: hello.pdf: can't find startxref
WARNING: hello.pdf: Attempting to reconstruct cross-reference table
hello.pdf: unable to find trailer dictionary while recovering damaged file
Where am I going wrong with this?
Many thanks in advance for any answers,
Cheers!
You should append a (syntactically correct) xref and trailer section to the end of the file. That means: each object in your PDF needs one line in the xref table, even if the byte offset isn't correctly stated. Then Ghostscript, pdftk or qpdf can re-establish a correct xref and render the file:
[...]
endobj
xref
0 8
0000000000 65535 f
0000000010 00000 n
0000000020 00000 n
0000000030 00000 n
0000000040 00000 n
0000000050 00000 n
0000000060 00000 n
0000000070 00000 n
trailer
<</Size 8/Root 1 0 R>>
startxref
555
%%EOF
Ah damn it - I had copied just a part of the code; the OP code is the one on pg 701 - then there is a footer which confused me; otherwise the code continues on pg 702 :/
(EDIT: also see Introduction to PDF - GNUpdf (archive) for a similar, more detailed example)
So here is the complete code:
%PDF-1.4
1 0 obj
<< /Type /Catalog
/Outlines 2 0 R
/Pages 3 0 R
>>
endobj
2 0 obj
<< /Type /Outlines
/Count 0
>>
endobj
3 0 obj
<< /Type /Pages
/Kids [ 4 0 R ]
/Count 1
>>
endobj
4 0 obj
<< /Type /Page
/Parent 3 0 R
/MediaBox [ 0 0 612 792 ]
/Contents 5 0 R
/Resources << /ProcSet 6 0 R
/Font << /F1 7 0 R >>
>>
>>
endobj
5 0 obj
<< /Length 73 >>
stream
BT
/F1 24 Tf
100 100 Td
( Hello World ) Tj
ET
endstream
endobj
6 0 obj
[ /PDF /Text ]
endobj
7 0 obj
<< /Type /Font
/Subtype /Type1
/Name /F1
/BaseFont /Helvetica
/Encoding /MacRomanEncoding
>>
endobj
xref
0 8
0000000000 65535 f
0000000009 00000 n
0000000074 00000 n
0000000120 00000 n
0000000179 00000 n
0000000364 00000 n
0000000466 00000 n
0000000496 00000 n
trailer
<< /Size 8
/Root 1 0 R
>>
startxref
625
%%EOF
Indeed, as the error messages were saying, xref section was missing!
However, this is still not the end - while this document will open in evince, evince will still complain:
$ evince hello.pdf
Error: PDF file is damaged - attempting to reconstruct xref table...
... and so will qpdf:
$ qpdf --check hello.pdf
WARNING: hello.pdf: file is damaged
WARNING: hello.pdf (file position 625): xref not found
WARNING: hello.pdf: Attempting to reconstruct cross-reference table
checking hello.pdf
PDF Version: 1.4
File is not encrypted
File is not linearized
WARNING: hello.pdf (object 5 0, file position 436): attempting to recover stream length
So to actually get a proper example, as the Adobe Forums: Simple Text String Example in specification broken. points out, xref table needs to be reconstructed (have correct byte offsets).
And in order to do this, we can use pdftk to "Repair a PDF's Corrupted XREF Table and Stream Lengths (If Possible)":
$ pdftk hello.pdf output hello_repair.pdf
... and now hello_repair.pdf opens in evince without a problem - and qpdf reports:
$ qpdf --check hello_repair.pdf
checking hello_repair.pdf
PDF Version: 1.4
File is not encrypted
File is not linearized
No errors found
Well, hope this helps someone,
Cheers!

Resources