105 lines
6.9 KiB
Plaintext
105 lines
6.9 KiB
Plaintext
|
|
Episode: 962
|
||
|
|
Title: HPR0962: LiTS 004: paste
|
||
|
|
Source: https://hub.hackerpublicradio.org/ccdn.php?filename=/eps/hpr0962/hpr0962.mp3
|
||
|
|
Transcribed: 2025-10-08 05:40:17
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
Welcome to Linux in the Shell, episode 4, the paste command.
|
||
|
|
My name is Dan Washco, and I will be your host, and up front I want to thank Hacker Public
|
||
|
|
Radio for supporting my efforts in the show, and I hope you enjoy it, but I also hope
|
||
|
|
that you go over and visit the website and read the entry for episode 4 of the paste command,
|
||
|
|
either before listening to this audio or soon afterwards to solidify the paste command
|
||
|
|
in your mind.
|
||
|
|
Paste command is a very simple command, and what it does is it takes one or more files
|
||
|
|
and pastes the line, each of the lines of those files together, consecutively.
|
||
|
|
So for instance, you can have two text files, let's say the first text file has A on
|
||
|
|
one line, B on another line, C on a third line, and D on a fourth line, and then the second
|
||
|
|
text file has numbers.
|
||
|
|
One on one, the first line, two on the second line, three on the third line, a four on
|
||
|
|
the fourth line.
|
||
|
|
So if you were to specify paste, file one, file two, you would get the output would show
|
||
|
|
A, tab one, the next line would be B, tab two, and then C, tab three, four, tab D. Well,
|
||
|
|
D, tab four, sorry, it makes that up.
|
||
|
|
So essentially what it does is it takes those two files and pastes each line of those files
|
||
|
|
together consecutively.
|
||
|
|
Now you can specify more than two files, you can paste as many files together as you want.
|
||
|
|
So let's make it easier on my tongue and say file one has numbers, file two has letters,
|
||
|
|
and file three has flowers, and we'll say daisy, tulip, violet, sunflower.
|
||
|
|
So if we were to paste all three of those files together, you would get one tab, A, tab,
|
||
|
|
daisy, two tab, B, tab, tulip, three tab, C, tab, violet, and four tab, D, tab, sunflower.
|
||
|
|
Very simple.
|
||
|
|
You can specify a delimiter instead of the tab which is a default by passing the option
|
||
|
|
dash dash delimiters, and that's plural equals and then delimiter in double quotes.
|
||
|
|
So for instance, if I were to do the same thing I just said, paste dash dash delimiters
|
||
|
|
equal open double quote, comma, close double quote, and then file one, two, three, what
|
||
|
|
I would get would be instead of tab separating them, commas.
|
||
|
|
So I would get one comma, A, comma, tulip, two comma, B, comma, violet, and so on.
|
||
|
|
Now understand that delimiters, if you specify just one, that's the one that's going to use.
|
||
|
|
As you can specify a delimiter, a list of delimiters to go between each input or file.
|
||
|
|
So for instance, in the case I just said, I could have passed as delimiters, comma, and
|
||
|
|
then equal sign, really odd thing, but what would happen is I would get, when I pasted
|
||
|
|
those together, paste dash dash delimiters equal open double quote, comma, equal sign, closed
|
||
|
|
double quote, file one, two, and three, I would get one comma, A equals tulip, two comma,
|
||
|
|
B equals, daisy, whatever the flower was, not can't remember what the flowers are, but
|
||
|
|
you get the picture.
|
||
|
|
It specifies it uses the delimiters that you specify in order.
|
||
|
|
Now if it just so happens that you specified a third delimiter in this case, say a question
|
||
|
|
mark, what happened then is it would just ignore that third delimiter and not use it.
|
||
|
|
So you would just get the comma and the equal sign being used, and it would just ignore
|
||
|
|
that third delimiter unless you add it on a fourth file.
|
||
|
|
Now there's one other option that the paste command takes, and that's the dash s option,
|
||
|
|
and that's to serialize what you wrote or what's being pasted together.
|
||
|
|
So instead of the output being the file, line one, pasted with line two right next to
|
||
|
|
it, it would kind of turn it on its head and represent that instead of it being vertical,
|
||
|
|
it would be horizontal.
|
||
|
|
So line one would be the entire file, but each line would be rep on a horizontal line,
|
||
|
|
would be the horizontal line.
|
||
|
|
So if I were to pass the dash s with the delimiters of comma delimiters to the paste using file
|
||
|
|
one, two, and three, what I would get on line one is the numbers one, two, three, four,
|
||
|
|
all separated by commas.
|
||
|
|
And then on line two, I would get a comma b, comma c, comma d.
|
||
|
|
And then on line three, I would get the flowers, daisy comma, tulip comma, violet comma,
|
||
|
|
sunflower.
|
||
|
|
So it would kind of an odd way of doing it, but that's what it does serialize it.
|
||
|
|
Instead of representing it in columnar format, it represents it out in rows, horizontally.
|
||
|
|
Each line is, you know, each line of that one file is on the same line.
|
||
|
|
And then underneath it is the next line of there.
|
||
|
|
So kind of flips it and reverses it on his head.
|
||
|
|
The last thing I want to say about the paste command is that it's supposed to passing
|
||
|
|
all files, you can pass standard in by representing it with a dash.
|
||
|
|
So instead of a file name, if you have a dash in there as one of the places of a file,
|
||
|
|
it's going to allow you to accept input from standard in now.
|
||
|
|
That would be an example would be to echo or cat another file or something, something
|
||
|
|
that has output in the format that you're looking for, it's going to produce lines.
|
||
|
|
And pipe that into the paste command, or if you don't have something, a command or action
|
||
|
|
piping something into the paste command is going to accept standard in from the keyboard.
|
||
|
|
And you could do that yourself, you would type paste text file one, which is the numbers,
|
||
|
|
and then dash, and it's going to present you with a prompt waiting for you to enter something.
|
||
|
|
So then it would echo back out that line and doing it that way, you can see how it works,
|
||
|
|
but it's really not too practical or useful.
|
||
|
|
So that's basically the paste command, very simple command, paste files, or together
|
||
|
|
line by line, you can specify a delimiter or a chain of delimiters, make sure they're
|
||
|
|
in double quotes by default that you use this tab, or you can specify a bunch of files
|
||
|
|
and standard in and place it one of those files.
|
||
|
|
I thank you for listening, again, check out the website so you can get a read up on this
|
||
|
|
and probably get a better picture of how the serial works, that's something more visual
|
||
|
|
than representing it verbally.
|
||
|
|
And also gives you the opportunity to check out the video that corresponds with this entry,
|
||
|
|
so you can see it in action.
|
||
|
|
My name is Dan Walshko, I thank you, see you in two weeks, and I really thank Hacker
|
||
|
|
Public Radio.
|
||
|
|
Have a great day.
|
||
|
|
You have been listening to Hacker Public Radio at HackerPublicRadio.org.
|
||
|
|
We are a community podcast network that releases shows every weekday on day through Friday.
|
||
|
|
Today's show, like all our shows, was contributed by a HBR listener by yourself.
|
||
|
|
If you ever consider recording a podcast, then visit our website to find out how easy
|
||
|
|
it really is.
|
||
|
|
Hacker Public Radio was founded by the Digital.Pound and the Infonomicom Computer Club.
|
||
|
|
HBR is funded by the binary revolution at binref.com, all binref projects are crowd-sponsored
|
||
|
|
by linear pages.
|
||
|
|
From shared hosting to custom private clouds, go to lunarpages.com for all your hosting
|
||
|
|
needs.
|
||
|
|
On list, otherwise stasis, today's show is released under a creative comments, attribution,
|
||
|
|
share a like, free dose of license.
|