cut and paste had always been there... ========================================== You know, when somebody thinks of "cut-and-paste" today, pointers and windows will quite likely spring to their mind. But actually, cut-and-paste is far older than mice ad GUIs. In any standard unix system there are two little programs that are meant to be used to cut and paste text, And guess what: they are called "cut" and "paste". Their usage is fairly simple: cut(1) can split a file in columns, and paste(1) can stitch together files side-by-side. Obviously, both cut(1) and paste(1) can get their input from standard input. But let's look at a simple example. $ stat -l * -rw-r--r-- 1 katolaz katolaz 737 Jan 21 20:59:13 2019 20190121_phlog.txt -rw-r--r-- 1 katolaz katolaz 1123 Jan 22 23:07:26 2019 20190122_cutpaste.txt -rw-r--r-- 1 katolaz katolaz 2583 Jan 21 20:59:08 2019 about.txt -rw-r--r-- 1 katolaz katolaz 1925 Jan 21 22:56:25 2019 gophermap -rw-r--r-- 1 katolaz katolaz 7934 Jan 22 23:28:05 2019 port70_2.png -rw-r--r-- 1 katolaz katolaz 4025 Jan 22 23:28:03 2019 port70_2.svg $ The command stat(1) gets some info about the files specified as arguments, (in this case, all the files in the current directory), and provides those info on output by separating fields with spaces. We can use cut(1) on the output of stat(1) to only show the owner, size, and name of each file: $ stat -l * | cut -d " " -f 3,5,10 katolaz 737 20190121_phlog.txt katolaz 1139 20190122_cutpaste.txt katolaz 2583 about.txt katolaz 1925 gophermap katolaz 7934 port70_2.png katolaz 4025 port70_2.svg $ where the option '-d " "' specifies which character we would like cut(1) to use as a separator (in this case a space, while the default is [TAB]). The option '-f 3,5,10' selects the 3rd, 5th, and 10th field on each line, counting from 1. For convenience, we will save the results into a file: $ stat -l * | cut -d " " -f 3,5,10 > /tmp/tmp_1 Similarly, we could also retrieve the type of each of the files in the current directory using the command file(1): $ file -N * 20190121_phlog.txt: ASCII text 20190122_cutpaste.txt: ASCII text about.txt: ASCII text gophermap: ASCII text port70_2.png: PNG image data, 425 x 360, 8-bit/color RGBA,non-interlaced port70_2.svg: SVG Scalable Vector Graphics image $ If we just want to keep the type of each file, we can use cut(1) again: $ file -N * | cut -d ":" -f 2 ASCII text ASCII text ASCII text ASCII text PNG image data, 425 x 360, 8-bit/color RGBA, non-interlaced SVG Scalable Vector Graphics image $ notice that the "useful" separator this time is ":", and we specified that we need the second field. Let us save everything in a second file: $ file -N * | cut -d ":" -f 2 > /tmp/tmp_2 What if we want to stitch together the results of stat(1) and file(1)? It's as simple as: $ paste /tmp/tmp_1 /tmp/tmp_2 katolaz 737 20190121_phlog.txt ASCII text katolaz 2534 20190122_cutpaste.txt ASCII text katolaz 2583 about.txt ASCII text katolaz 1925 gophermap ASCII text katolaz 7934 port70_2.png PNG image data, 425 x 360, 8-bit/color RGBA, non-interlaced katolaz 4025 port70_2.svg SVG Scalable Vector Graphics image $ which is exactly what we would have expected. The only issue with this is that paste(1) uses a [TAB] as a default separator, which in this case messes the output up a bit. Let's replace it with a space: $ paste -d " " /tmp/tmp_1 /tmp/tmp_2 katolaz 737 20190121_phlog.txt ASCII text katolaz 2534 20190122_cutpaste.txt ASCII text katolaz 2583 about.txt ASCII text katolaz 1925 gophermap ASCII text katolaz 7934 port70_2.png PNG image data, 425 x 360, 8-bit/color RGBA, non-interlaced katolaz 4025 port70_2.svg SVG Scalable Vector Graphics image $ Notice how the ancient dwarves were so wise to use the same option (-d) to indicate the same function (specify the separator) in two commands that are often run together (cut(1) and paste(1)). -+-+-+-+-