unix

create unix alias using a python3 script

好久不见. 提交于 2021-02-05 09:11:23
问题 Well, as we all known, creating an alias in a terminal shell is quite easy: ZZ:~ zhangzhao$ alias c='uname' ZZ:~ zhangzhao$ c Darwin ZZ:~ zhangzhao$ But now I want to do the same thing through a Python3 script. I've checked the ref manual and found these sort of command work can be solved using subprocess module. Then I write the script below: import subprocess subprocess.call(["alias", "c=\'uname\'"]) But note that this operation will not take effect to the shell you are currently using,

create unix alias using a python3 script

百般思念 提交于 2021-02-05 09:06:09
问题 Well, as we all known, creating an alias in a terminal shell is quite easy: ZZ:~ zhangzhao$ alias c='uname' ZZ:~ zhangzhao$ c Darwin ZZ:~ zhangzhao$ But now I want to do the same thing through a Python3 script. I've checked the ref manual and found these sort of command work can be solved using subprocess module. Then I write the script below: import subprocess subprocess.call(["alias", "c=\'uname\'"]) But note that this operation will not take effect to the shell you are currently using,

How to extract ppl of this custom program?

痞子三分冷 提交于 2021-02-05 08:53:06
问题 I have a program that when I run, it prints something like this in command line: file test.test: 427 sentences, 2433 words, 1186 OOVs 0 zeroprobs, logprob= -4914.55 ppl= 862.603 ppl1= 8731.65 But I only want to save the number 862.603 in an environment variable. How can I extract that single number from output of the program? 回答1: Every answer I've seen thus far has had some deficiency, so I guess I'll go ahead and add this to the mix: There are a couple of ways to do this. My preferred way

How to make a comparison between sentences and calculate the similarity?

馋奶兔 提交于 2021-02-05 07:36:17
问题 How to make a comparison between the first sentence of the second sentence and the first sentence with the third sentence and so on, and calculate the similarity using shell script or bash I have a sentences containing duplicate words, for example, the input data in file my_text.txt and should ignore duplicated words per sentence, filler words, and non-alphabetical characters. Shell Script Linux Shell Script Shell or bash are fun I used this shell script to find similarity words=$( < my_text

How to make a comparison between sentences and calculate the similarity?

佐手、 提交于 2021-02-05 07:36:01
问题 How to make a comparison between the first sentence of the second sentence and the first sentence with the third sentence and so on, and calculate the similarity using shell script or bash I have a sentences containing duplicate words, for example, the input data in file my_text.txt and should ignore duplicated words per sentence, filler words, and non-alphabetical characters. Shell Script Linux Shell Script Shell or bash are fun I used this shell script to find similarity words=$( < my_text

How to move first column to last column in unix?

淺唱寂寞╮ 提交于 2021-02-05 06:37:26
问题 This is the data in a text file. 0.354167 male atyp_angina 0.066038 0.1621 t normal 0.648855 no 0 up 0 reversable_defect <50 0.625 male typ_angina 0.792453 0.328767 f left_vent_hyper 0.564885 no 0.677419 down 0 reversable_defect <50 0.645833 male non_anginal 0.433962 0.134703 f left_vent_hyper 0.641221 no 0.483871 flat 0 normal >50_1 0.666667 female asympt 0.481132 0.413242 f left_vent_hyper 0.572519 yes 0.16129 flat 0 reversable_defect >50_1 0.270833 male typ_angina 0.509434 0.269406 f left

OpenProcess/ReadProcessMemory/WriteProcessMemory/CloseHandle equivalent

你。 提交于 2021-02-05 05:46:06
问题 What would be the equivalent api to these Windows functions? In case you are not familiar with the windows functions, all they do is open a process, access(read and write) its memory and close its handle. Can this be done with syscalls only as well? 回答1: You're looking for ptrace. Despite the name, it will also target individual threads on Linux and possibly other systems. More info can be found with Google if that blog post doesn't help. 回答2: If you're on a more modern kernel, you might try

OpenProcess/ReadProcessMemory/WriteProcessMemory/CloseHandle equivalent

女生的网名这么多〃 提交于 2021-02-05 05:46:06
问题 What would be the equivalent api to these Windows functions? In case you are not familiar with the windows functions, all they do is open a process, access(read and write) its memory and close its handle. Can this be done with syscalls only as well? 回答1: You're looking for ptrace. Despite the name, it will also target individual threads on Linux and possibly other systems. More info can be found with Google if that blog post doesn't help. 回答2: If you're on a more modern kernel, you might try

How to execute 4 shell scripts in parallel, I can't use GNU parallel?

风流意气都作罢 提交于 2021-02-04 21:35:42
问题 I have 4 shell scripts dog.sh, bird.sh, cow.sh and fox.sh. Each of these files execute 4 wgets in parallel using xargs to fork a separate process. Now I want these scripts themselves to be executed in parallel. For some portability reason unknown to me I can't use GNU parallel. IS there a way I can do this with xargs or with any other tool. Also can I also ask what could the portability reason be? I'm a total newbie to shell scripting. Sorry if my question seems cryptic. Thanks in advance

Get Monday and Sunday etc.. for a week for any date as parameter in Unix

吃可爱长大的小学妹 提交于 2021-02-04 18:40:09
问题 How to get the date of Monday and Sunday in a week for a date? This gives date for 'last' monday: date -dlast-monday +%Y%m%d I want to pass a date as parameter to find the Monday and Sunday for that week. Basically, I want to get Sunday and Monday for a week, for ANY date, NOT only for last monday . 回答1: Try this: export day=2013-10-01 date -d "$day -$(date -d $day +%w) days" This will always print the Sunday before the given date (or the date itself). date -d "$day -$(date -d $day +%u) days"