unix

sorting with multiple keys with Linux sort command

冷暖自知 提交于 2021-02-07 03:00:17
问题 Say I have this file. $ cat a.txt c 1002 4 f 1001 1 d 1003 1 a 1001 3 e 1004 2 b 1001 2 I want to sort it by the second column and then by the third column. Column two are numbers, while column 3 can be treated as string. I know the following command works well. $ sort -k2,2n -k3,3 a.txt f 1001 1 b 1001 2 a 1001 3 c 1002 4 d 1003 1 e 1004 2 However, I think sort -k2n a.txt should also work, while it does not. $ sort -k2n a.txt a 1001 3 b 1001 2 f 1001 1 c 1002 4 d 1003 1 e 1004 2 Seems like

sorting with multiple keys with Linux sort command

二次信任 提交于 2021-02-07 03:00:09
问题 Say I have this file. $ cat a.txt c 1002 4 f 1001 1 d 1003 1 a 1001 3 e 1004 2 b 1001 2 I want to sort it by the second column and then by the third column. Column two are numbers, while column 3 can be treated as string. I know the following command works well. $ sort -k2,2n -k3,3 a.txt f 1001 1 b 1001 2 a 1001 3 c 1002 4 d 1003 1 e 1004 2 However, I think sort -k2n a.txt should also work, while it does not. $ sort -k2n a.txt a 1001 3 b 1001 2 f 1001 1 c 1002 4 d 1003 1 e 1004 2 Seems like

First character of a variable in a shell script to uppercase?

这一生的挚爱 提交于 2021-02-06 15:29:33
问题 I have a shell script that starts unit tests for modules. I need the name of the module in all lowercase and with the first character uppercase. So far I have been doing it like this: #!/bin/sh -x # z.B. getbrowser strModuleToTest=$1 # g strModuleToTestUppercaseFirstletter=${strModuleToTest:0:1} # etbrowser strModuleToTestUppercaseLastletters=${strModuleToTest:1} # g -> G strModuleToTestUppercaseFirstletter="${strModuleToTestUppercaseFirstletter/a/A}" strModuleToTestUppercaseFirstletter="$

First character of a variable in a shell script to uppercase?

蓝咒 提交于 2021-02-06 15:26:53
问题 I have a shell script that starts unit tests for modules. I need the name of the module in all lowercase and with the first character uppercase. So far I have been doing it like this: #!/bin/sh -x # z.B. getbrowser strModuleToTest=$1 # g strModuleToTestUppercaseFirstletter=${strModuleToTest:0:1} # etbrowser strModuleToTestUppercaseLastletters=${strModuleToTest:1} # g -> G strModuleToTestUppercaseFirstletter="${strModuleToTestUppercaseFirstletter/a/A}" strModuleToTestUppercaseFirstletter="$

Python equivalent of unix cksum function

前提是你 提交于 2021-02-06 15:18:01
问题 I've been looking for the equivalent python method for the unix cksum command: http://pubs.opengroup.org/onlinepubs/7990989775/xcu/cksum.html $ cksum ./temp.bin 1605138151 712368 ./temp.bin So far I have found the zlib.crc32() function >>> import zlib >>> f = open('./temp.bin','rb') >>> data = f.read() >>> zlib.crc32(data) 1128751837 However this code appears to produce different results. As far as I can tell this should be using the same crc polynomial but I imagine there must be some

what is “tty” on FreeBSD?

三世轮回 提交于 2021-02-06 13:51:43
问题 "uprintf() function outputs to the current process' controlling tty" This is description of uprintf() from Freebsd MAN. I don't understand what is tty? Thanks.Nice holiday! 回答1: A tty is an abstract model of a character I/O device. It is most directly a system interface, with corresponding application program interfaces. Once upon a time there was a corporation named Teletype . They made hardcopy automatic typewriter devices that were used as communications terminals for decades and then

what is “tty” on FreeBSD?

只愿长相守 提交于 2021-02-06 13:50:36
问题 "uprintf() function outputs to the current process' controlling tty" This is description of uprintf() from Freebsd MAN. I don't understand what is tty? Thanks.Nice holiday! 回答1: A tty is an abstract model of a character I/O device. It is most directly a system interface, with corresponding application program interfaces. Once upon a time there was a corporation named Teletype . They made hardcopy automatic typewriter devices that were used as communications terminals for decades and then

what is “tty” on FreeBSD?

女生的网名这么多〃 提交于 2021-02-06 13:50:23
问题 "uprintf() function outputs to the current process' controlling tty" This is description of uprintf() from Freebsd MAN. I don't understand what is tty? Thanks.Nice holiday! 回答1: A tty is an abstract model of a character I/O device. It is most directly a system interface, with corresponding application program interfaces. Once upon a time there was a corporation named Teletype . They made hardcopy automatic typewriter devices that were used as communications terminals for decades and then

Why does Linux use getdents() on directories instead of read()?

给你一囗甜甜゛ 提交于 2021-02-06 11:22:30
问题 I was skimming through K&R C and I noticed that to read the entries in a directories, they used: while (read(dp->fd, (char *) &dirbuf, sizeof(dirbuf)) == sizeof(dirbuf)) /* code */ Where dirbuf was a system-specific directory structure, and dp->fd a valid file descriptor. On my system, dirbuf would have been a struct linux_dirent . Note that a struct linux_dirent has a flexible array member for the entry name, but let us assume, for the sake of simplicity, that it doesn't. (Dealing with the

Why does Linux use getdents() on directories instead of read()?

南笙酒味 提交于 2021-02-06 11:21:31
问题 I was skimming through K&R C and I noticed that to read the entries in a directories, they used: while (read(dp->fd, (char *) &dirbuf, sizeof(dirbuf)) == sizeof(dirbuf)) /* code */ Where dirbuf was a system-specific directory structure, and dp->fd a valid file descriptor. On my system, dirbuf would have been a struct linux_dirent . Note that a struct linux_dirent has a flexible array member for the entry name, but let us assume, for the sake of simplicity, that it doesn't. (Dealing with the