unix

Unix - combine all rows into a comma-separated single row

女生的网名这么多〃 提交于 2020-05-25 05:40:57
问题 I have following values in a file in separate lines: California New York Washington South Carolina Kansas What would be unix script to display them in a single line (as showb below) 'California', 'New York', 'Washington', 'South Carolina', 'Kansas' [I do not want to have any intermediate file to achieve this.. just an echo code is fine] 回答1: Use this command tr '\n' ',' < input_file For single quotes use sed -e "s/^/'/" input_file | sed -e "s/$/'/" | tr '\n' ',' (Not tested for single/double

Unix - combine all rows into a comma-separated single row

*爱你&永不变心* 提交于 2020-05-25 05:38:05
问题 I have following values in a file in separate lines: California New York Washington South Carolina Kansas What would be unix script to display them in a single line (as showb below) 'California', 'New York', 'Washington', 'South Carolina', 'Kansas' [I do not want to have any intermediate file to achieve this.. just an echo code is fine] 回答1: Use this command tr '\n' ',' < input_file For single quotes use sed -e "s/^/'/" input_file | sed -e "s/$/'/" | tr '\n' ',' (Not tested for single/double

Remove consecutive duplicate words from a file using awk or sed

♀尐吖头ヾ 提交于 2020-05-23 11:40:08
问题 My input file looks like below: “true true, rohith Rohith; cold burn, and fact and fact good good?” Output shoud look like: "true, rohith Rohith; cold burn, and fact and fact good?" i am trying the same with awk, but couldn't able to get the desired result. awk '{for (i=1;i<=NF;i++) if (!a[$i]++) printf("%s ",$i,FS)}{printf("\n")}' input.txt Could someone please help me here. Regards, Rohith 回答1: With GNU awk for the 4th arg to split(): $ cat tst.awk { n = split($0,words,/[^[:alpha:]]+/,seps)

Difference between 'Killed' and 'Terminated'

别等时光非礼了梦想. 提交于 2020-05-23 04:16:28
问题 I was just testing kill switch flags with a sleeping process. First i tried killed it with -15 xtechkid@ubuntu:~/Desktop/expermiments$ ps cax | grep 10005 10005 pts/2 S+ 0:00 sh xtechkid@ubuntu:~/Desktop/expermiments$ kill -15 10005 And the process got terminated xtechkid@ubuntu:~/Desktop/expermiments$ sh testscript.sh This is a script which sleeps for few seconds .. Terminated Then i killed it with - 9 xtechkid@ubuntu:~/Desktop/expermiments$ ps -ef | grep testscript.sh xtechkid 10059 9852 0

UNIX domain datagram - “Invalid argument” on sendto

孤人 提交于 2020-05-17 05:59:07
问题 I am constructing UNIX domain datagram sockets to pass messages from one thread to another thread in the same program. The socket code is written in C and it's called from NASM. Sendto returns (through perror) "socket: Invalid argument." Here is the code for sendto: ssize_t client_send(int64_t sfd, const void * buf, int64_t msgLen, const void * svaddr) { ssize_t result = sendto(sfd, buf, msgLen, 0, (struct sockaddr *) &svaddr, sizeof(struct sockaddr_un)); perror("socket"); if (result !=

keep fasta records which have 2 matches of OX values

╄→гoц情女王★ 提交于 2020-05-16 22:05:49
问题 I have a file that looks as follows : >sp|rin-1 ghsfdhjkuesl OX=10116 GN=Cdh1 PE=1 SV=1|sp|P10287|ghsfdjdeosd gdhkhs OX=10090 GN=Cdh3 PE=1 SV=2 WRDTANWLEINPETGVISTRAEMDREDSEHVKNSTYTALIIATDDGSPIATGTGTLLLVLSDVNDNAPIPEPRNMQFCQRNPKPHVITILDPDLPP >sp|erin-1 ghsfdshkd OX=10116 GN=Cdh1 PE=1 SV=1|sp|P22223|CADH3_HUMAN Cadherin-3 OX=9606 GN=CDH3 PE=1 SV=2 ESYPTYTLVVQAADLQGEGLSTTAKAVITVKDINDNAPIFNPSTYLQCAASEPCRAVFREAEVTLEAGGAEQEPGQALGKVFMGCPGQEPALFSTD >sp|n-1 ghsfd OX=10116 GN=Cdh1 PE=1 SV=1|tr|F1LMI3

keep fasta records which have 2 matches of OX values

怎甘沉沦 提交于 2020-05-16 22:05:17
问题 I have a file that looks as follows : >sp|rin-1 ghsfdhjkuesl OX=10116 GN=Cdh1 PE=1 SV=1|sp|P10287|ghsfdjdeosd gdhkhs OX=10090 GN=Cdh3 PE=1 SV=2 WRDTANWLEINPETGVISTRAEMDREDSEHVKNSTYTALIIATDDGSPIATGTGTLLLVLSDVNDNAPIPEPRNMQFCQRNPKPHVITILDPDLPP >sp|erin-1 ghsfdshkd OX=10116 GN=Cdh1 PE=1 SV=1|sp|P22223|CADH3_HUMAN Cadherin-3 OX=9606 GN=CDH3 PE=1 SV=2 ESYPTYTLVVQAADLQGEGLSTTAKAVITVKDINDNAPIFNPSTYLQCAASEPCRAVFREAEVTLEAGGAEQEPGQALGKVFMGCPGQEPALFSTD >sp|n-1 ghsfd OX=10116 GN=Cdh1 PE=1 SV=1|tr|F1LMI3

keep fasta records which have 2 matches of OX values

烂漫一生 提交于 2020-05-16 22:05:02
问题 I have a file that looks as follows : >sp|rin-1 ghsfdhjkuesl OX=10116 GN=Cdh1 PE=1 SV=1|sp|P10287|ghsfdjdeosd gdhkhs OX=10090 GN=Cdh3 PE=1 SV=2 WRDTANWLEINPETGVISTRAEMDREDSEHVKNSTYTALIIATDDGSPIATGTGTLLLVLSDVNDNAPIPEPRNMQFCQRNPKPHVITILDPDLPP >sp|erin-1 ghsfdshkd OX=10116 GN=Cdh1 PE=1 SV=1|sp|P22223|CADH3_HUMAN Cadherin-3 OX=9606 GN=CDH3 PE=1 SV=2 ESYPTYTLVVQAADLQGEGLSTTAKAVITVKDINDNAPIFNPSTYLQCAASEPCRAVFREAEVTLEAGGAEQEPGQALGKVFMGCPGQEPALFSTD >sp|n-1 ghsfd OX=10116 GN=Cdh1 PE=1 SV=1|tr|F1LMI3

How to fix a segmentation fault: 11 in c++?

风格不统一 提交于 2020-05-14 10:05:05
问题 I am currently working on a program that takes the mode from an array of numbers using a template function. The code will compile with no problems using g++ on my macOS (i.e. no errors, warnings, etc.). However when I run the code I get this output in the terminal: Segmentation fault: 11 Here is the code that I have: #include <stdexcept> #include <cstdio> #include <cstddef> template<typename T> T mode(const T* values, size_t length) { if (length < 0) throw std::out_of_range{ 0 }; T result{};

proper way of handling std::thread termination in child process after fork()

荒凉一梦 提交于 2020-05-13 14:45:11
问题 Frown as much as you want, I'm going to do it anyway :) My question is: in the following code, what is the proper way to handle the termination of the std::thread in the subprocess generated by fork() ? std::thread::detach() or std::thread::join() ? #include <thread> #include <iostream> #include <unistd.h> struct A { void Fork() { std::thread t(&A::Parallel, this); pid_t pid = fork(); if(pid) { //parent t.join(); } else { //child t.join(); // OR t.detach()? } } void Parallel() { std::cout <<