unix

join all lines that have the same first column to the same line

拟墨画扇 提交于 2020-01-16 03:49:07
问题 IE: File: 1234:abcd 1234:930 1234:999999 194:keee 194:284 194:222222 Result: 1234:abcd:930:999999 194:kee:284:222222 I have exhausted my brain to the best of my knowledge and can't come up with a way. Sorry to bother you guys! 回答1: $ awk -F: '$1==last {printf ":%s",$2; next} NR>1 {print "";} {last=$1; printf "%s",$0;} END{print "";}' file 1234:abcd:930:999999 194:keee:284:222222 How it works -F: This tells awk to use a : as the field separator. $1==last {printf ":%s",$2; next} If the first

join all lines that have the same first column to the same line

坚强是说给别人听的谎言 提交于 2020-01-16 03:49:05
问题 IE: File: 1234:abcd 1234:930 1234:999999 194:keee 194:284 194:222222 Result: 1234:abcd:930:999999 194:kee:284:222222 I have exhausted my brain to the best of my knowledge and can't come up with a way. Sorry to bother you guys! 回答1: $ awk -F: '$1==last {printf ":%s",$2; next} NR>1 {print "";} {last=$1; printf "%s",$0;} END{print "";}' file 1234:abcd:930:999999 194:keee:284:222222 How it works -F: This tells awk to use a : as the field separator. $1==last {printf ":%s",$2; next} If the first

Why is my mac terminal's ps -u not working?

北城余情 提交于 2020-01-16 02:26:26
问题 I am learning the Linux ps command and its possible arguments. My tutorial told me about the -u argument and I am trying to use it. No matter if I use it alone or with other args, it is throwing errors. I am inserting a picture of the output I keep receiving. I'm not sure if this is something to do with my Mac's terminal/shell, or if I am missing something that I should be typing. It seems to be telling me to use two hyphens, --u, instead of one, -u, but it gives me the same issue. If I JUST

Replace all Occurences of '.' with '_' before '=' using sed

冷暖自知 提交于 2020-01-16 01:53:20
问题 I have a properties file as below: build.number=153013 db.create.tablespace=0 db.create.user=0 db.create.schema=0 upgrade.install=1 new.install=0 configure.jboss=0 configure.jbosseap=false configure.weblogic=1 configure.websphere=0 I need to import these variables into a shell script. As you know, '.' is not a valid character to use as a variable in linux. How would I use sed to replace all occurrences of '.' before the '=' with '_' . I have replaced all occurrences of '.' but there are some

Inverted question mark(¿e) appears in unix variable after getting it from oracle query

北慕城南 提交于 2020-01-16 01:19:48
问题 I am assigning oracle query result to unix variable. In the query result the column has -e as value. When i assign this to a unix variable, it becomes ¿e . How to overcome this junk value? 回答1: The issue was with hyphen.. - / — . '—' is an invalid hyphen. I had corrected the same with '-' . The issue is resolved now. 来源: https://stackoverflow.com/questions/34761044/inverted-question-mark-e-appears-in-unix-variable-after-getting-it-from-oracle

How can I add signal handlers to a shell written in Py3k/Python?

坚强是说给别人听的谎言 提交于 2020-01-16 00:48:08
问题 I am working on writing a shell, but I want to have stubbed signal handlers when the user hits i.e. control-C or control-Z. My code is as follows; as I have investigated it, I can get it to not stop on a control-Z, but still suspend on a control-Z. The most recent published version of the code is at http://JonathansCorner.com/cjsh/download.cgi. The code I am working on is: def handle_signal(signal_number, frame): print (''' CJSH does not support the traditional and rather archaic methods of

Can I prevent a script from launching twice using open(2) with O_CREAT and flock(2)?

两盒软妹~` 提交于 2020-01-15 15:28:20
问题 I would like to prevent a script from launching twice by using a PID file. There are many ways to implement exclusivity, but since my script will always run on a Linux machine and I would like to be able to detect stale PID files automatically, I would like to use flock(2) to implement this. I was told long ago by a colleague that the following pseudocode is the right way to do this ( open(..., 'w') means "open in write mode with O_CREAT "): fd = open(lockfile, 'w'); write(fd, pid); close(fd)

Call system() inside forked (child) process, when parent process has many threads, sockets and IPC

五迷三道 提交于 2020-01-15 15:08:12
问题 I have a program that have many threads. Some threads are TCP servers... Each server fires new threads to handle any new connections. Inside one of the threads that handles a single client, I call fork(). The child process calls setpgid() (to create a new group) and then system() (the function of C/C++ standard library). The parent process keeps taking naps (usleep() function) and checking a time limit. If the time limit is exceeded before child process returns from system(), the parent

How to get the array name from a variable

女生的网名这么多〃 提交于 2020-01-15 12:22:19
问题 How to get the array name from the below ? Getting the name of the array from config : jobcfgUniqName=`echo ${config_data} | awk -F "#" '{print $3}'` Creating an array of it : for ((xx = 0; xx <= ${#joblognameSearch[@]}; xx++)) do print $joblognameSearch[$xx] eval ($jobcfgUniqName)[$xx]=`grep -B 3 -i error $joblogPath/$joblognameSearch[$xx]` print jobcfgUniqName : ${jobcfgUniqName} done This line I tried changing many ways but did not work : eval ($jobcfgUniqName)[$xx] 回答1: You can use

curl large file as POST request

北战南征 提交于 2020-01-15 11:48:34
问题 I have a number of ~10MB xml files on a local computer. For each file, I need to send it to a remote server for processing. The way I attempted to do this was by using curl to POST to a function: curl MyIP -d @my_file.xml Where MyIP is the url of the function that does the xml processing. However, this seems to be problematic, as most of the POST data is cut off due to some limitation (though I'm not sure what this limitation is). What would be the suggested way to send a ~10MB file to a