gnu-coreutils

Forcing the order of output fields from cut command

▼魔方 西西 提交于 2019-12-04 08:26:38
问题 I want to do something like this: cat abcd.txt | cut -f 2,1 and I want the order to be 2 and then 1 in the output. On the machine I am testing (FreeBSD 6), this is not happening (its printing in 1,2 order). Can you tell me how to do this? I know I can always write a shell script to do this reversing, but I am looking for something using the 'cut' command options. I think I am using version 5.2.1 of coreutils containing cut. 回答1: This can't be done using cut . According to the man page:

How to get all fields in outer join with Unix join?

瘦欲@ 提交于 2019-12-03 06:20:52
Suppose that I have two files, en.csv and sp.csv , each containing exactly two comma-separated records: en.csv : 1,dog,red,car 3,cat,white,boat sp.csv : 2,conejo,gris,tren 3,gato,blanco,bote If I execute join -t, -a 1 -a 2 -e MISSING en.csv sp.csv the output I get is: 1,dog,red,car 2,conejo,gris,tren 3,cat,white,boat,gato,blanco,bote Notice that all the missing fields have been collapsed. To get a "proper" full outer join, I need to specify a format; thus join -t, -a 1 -a 2 -e MISSING -o 0,1.2,1.3,1.4,2.2,2.3,2.4 en.csv sp.csv yields 1,dog,red,car,MISSING,MISSING,MISSING 2,MISSING,MISSING

Forcing the order of output fields from cut command

拜拜、爱过 提交于 2019-12-02 21:56:27
I want to do something like this: cat abcd.txt | cut -f 2,1 and I want the order to be 2 and then 1 in the output. On the machine I am testing (FreeBSD 6), this is not happening (its printing in 1,2 order). Can you tell me how to do this? I know I can always write a shell script to do this reversing, but I am looking for something using the 'cut' command options. I think I am using version 5.2.1 of coreutils containing cut. Lars Haugseth This can't be done using cut . According to the man page: Selected input is written in the same order that it is read, and is written exactly once. Patching

How to print the whole line that contains a specified byte offset in a file?

怎甘沉沦 提交于 2019-12-01 16:14:16
问题 I have such a example input.txt file: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Now I can

brew install coreutils failing 10.9.5 OSX

混江龙づ霸主 提交于 2019-12-01 13:08:58
It has been 2 days that I have failed to install coreutils . Last 15 lines from /Users/Mehdi/Library/Logs/Homebrew/coreutils/03.make: src/ginstall -c -m 644 'man/unlink.1' '/usr/local/Cellar/coreutils/8.27/share/man/man1/gunlink.1' src/ginstall -c src/uniq '/usr/local/Cellar/coreutils/8.27/bin/./guniq' src/ginstall -c -m 644 'man/vdir.1' '/usr/local/Cellar/coreutils/8.27/share/man/man1/gvdir.1' src/ginstall -c src/unlink '/usr/local/Cellar/coreutils/8.27/bin/./gunlink' src/ginstall -c src/vdir '/usr/local/Cellar/coreutils/8.27/bin/./gvdir' src/ginstall -c -m 644 'man/wc.1' '/usr/local/Cellar

In shell scripting, what does .[!.]* mean?

 ̄綄美尐妖づ 提交于 2019-12-01 05:56:11
A command that prints a list of files and folders in the current directory along with their total sizes is du -sh * . That command alone doesn't, however, list hidden files or folders. I found a solution for a command that does correctly list the hidden files and folders along with the rest: du -sh .[!.]* * . Although it works perfectly, the solution was provided as-is, without any explanation. What is the meaning of .[!.]* , exactly? How does it work? It's a globbing pattern that basically tells bash to find all files starting with a . , followed by any character but a . and containing any

How do locales work in Linux / POSIX and what transformations are applied?

一曲冷凌霜 提交于 2019-11-29 01:51:55
I'm working with huge files of (I hope) UTF-8 text. I can reproduce it using Ubuntu 13.10 (3.11.0-14-generic) and 12.04. While investigating a bug I've encountered strange behavoir $ export LC_ALL=en_US.UTF-8 $ sort part-r-00000 | uniq -d ɥ ɨ ɞ ɧ 251 ɨ ɡ ɞ ɭ ɯ 291 ɢ ɫ ɬ ɜ 301 ɪ ɳ 475 ʈ ʂ 565 $ export LC_ALL=C $ sort part-r-00000 | uniq -d $ # no duplicates found The duplicates also appear when running a custom C++ program that reads the file using std::stringstream - it fails due to duplicates when using en_US.UTF-8 locale. C++ seems to be unaffected at least for std::string and input/output.

How to extract the first two characters of a string in shell scripting?

北慕城南 提交于 2019-11-28 16:16:39
For example, given: USCAGoleta9311734.5021-120.1287855805 I want to extract just: US Probably the most efficient method, if you're using the bash shell (and you appear to be, based on your comments), is to use the sub-string variant of parameter expansion: pax> long="USCAGol.blah.blah.blah" pax> short="${long:0:2}" ; echo "${short}" US This will set short to be the first two characters of long . If long is shorter than two characters, short will be identical to it. This in-shell method is usually better if you're going to be doing it a lot (like 50,000 times per report as you mention) since

Less gets keyboard input from stderr?

梦想与她 提交于 2019-11-28 13:19:31
I'm taking a look at the code to the 'less' utility, specifically how it gets keyboard input. Interestingly, on line 80 of ttyin.c, it sets the file descriptor to read from: /* * Try /dev/tty. * If that doesn't work, use file descriptor 2, * which in Unix is usually attached to the screen, * but also usually lets you read from the keyboard. */ #if OS2 /* The __open() system call translates "/dev/tty" to "con". */ tty = __open("/dev/tty", OPEN_READ); #else tty = open("/dev/tty", OPEN_READ); #endif if (tty < 0) tty = 2; Isn't file descriptor 2 stderr? If so, WTH?! I thought keyboard input was

Display two files side by side

╄→尐↘猪︶ㄣ 提交于 2019-11-28 03:03:28
How can 2 unsorted text files of different lengths be display side by side (in columns) in a shell Given one.txt and two.txt : $ cat one.txt apple pear longer line than the last two last line $ cat two.txt The quick brown fox.. foo bar linux skipped a line Display: apple The quick brown fox.. pear foo longer line than the last two bar last line linux skipped a line paste one.txt two.txt almost does the trick but doesn't align the columns nicely as it just prints one tab between column 1 and 2. I know how to this with emacs and vim but want the output displayed to stdout for piping ect. The