|Home||Switchboard||Unix Administration||Red Hat||TCP/IP Networks||Neoliberalism||Toxic Managers|
May the source be with you, but remember the KISS principle ;-)
Skepticism and critical thinking is not panacea, but can help to understand the world better
The Unix paste command combines files horizontally into a single line.. For simple cases it is Ok. for complex cases you need to use Perl or AWK instead.
When two files are supplied as arguments, paste writes to standard output the first line of the first file, a Tab character, and the first line from the second file, and then continues with the second line until all the lines have been written out. If one file is shorter than the other, blank lines are used for the missing lines.
If you have two files, it would display the first file in the left column and the second file in the second column. The paste command has three main functions:
Following is the general format of the paste command.
paste [ -d[list] ] [-]file_list paste -s [ -d[list ] file_list
The following list describes the options and their arguments that may be used to control how paste functions.
|-||The standard input. Causes paste to read one file from the standard input.|
|-dlist||Delimiter. Allows you to define what character you want to use to separate columns of output. If you do not specify a list, the output columns are displayed immediately next to each other.|
|If -d is not specified, a tab character separates all columns.|
|The list is zero or more characters used for output delimiters, replacing the default tab character. The list must follow immediately after the -d option. If list consists of multiple characters, paste uses the first character to separate columns one and two, the second character between columns two and three, and so on. If the list is completely used and more columns exist, then the list is reused from the beginning. Thus it is a circular delimiter list.|
|The list may contain any of the following standard C escape sequences:|
|\\||A backslash; since a backslash is a special character you must escape it.|
|\0||No character at all. Same as -d without a list. But may be used in multi- character list. Does not actually place a character on the output.|
|You may have to quote the list to keep the shell from interpreting certain characters. For example, to pass a backslash to paste you would have to type -d"\\" or -d'\'.|
|-s||Serial output. Allows you to combine all lines of each file into one line of output. The -d option may be used to change the output delimiter. The last character of output is always a new-line.|
The following describes the argument that may be passed to the paste command.
|file_list||One or more files read and displayed in the appropriate format.|
DIAGNOSTICS AND BUGS
The following messages may be displayed if paste encounters a problem.
|line too long||An input line is too long. The longest possible input is 511 characters.|
|too many files||Only 12 input files can be specified; you entered 13 or more. The -s option is restricted by this limit.|
The --delimiters (-d) switch is a list of one or more delimiters to use in place of a Tab. The paste command cycles through the list if it needs more delimiters than are provided in the list, as shown below:
#!/bin/bash # # two_columns.sh shopt -s -o nounset declare -r ROBOTS="robots.txt" declare -r COLUMN1="column1.txt" declare -r COLUMN2="column2.txt" declare -i LINES LINES='wc -l < "$ROBOTS"' LINES=LINES/2 head -$LINES < "$ROBOTS" > "$COLUMN1" LINES=LINES+1 tail +$LINES < "$ROBOTS" > "$COLUMN2" paste --delimiters="|" "$COLUMN1" "$COLUMN2" rm "$COLUMN1" rm "$COLUMN2" exit 0
Suppose you had a file called order1.txt containing an item separated into a list of the fields on single lines.
Birchwood China Hutch 475.99 1 756
The paste --serial (-s) switch pastes all the lines of each file into a single item, as opposed to combining a single line from each file one line at a time. This switch recombines the separate fields into a single line.
$ paste --serial --delimiters="," order1.txt Birchwood China Hutch,475.99,1,756
To merge the lines of two or more files so that the lines follow one another, use the sort command with the -m switch.
cj> paste first city Name City Someone Austin Anyone Dallas
cj> paste -d: -s first second Name:Someone:Anyone:City:Austin:Dallas
cj> ls /bin | paste - - - - adb ar as basename . . .
The paste command can be used to paste lines from one or more files (one of them can be a standard input) to the standard output, which can be redirected to a file. The paste command concatenates the line from each input file to the output file separating them by the tab character (default).
Following is a list of flags that can be used with the paste command:
- -dlist to specify characters that will be used to separate corresponding lines from the input files in the output file. You can specify multiple characters if you have multiple input files.
- -s to merge subsequent lines from input file for each input file, one at a time, separated by the specified delimiter character.
Examples Let us assume that we have two files, file1 and file2, whose contents are shown below:more file1 computer1 16MB 1.2GB 17inch CDROM computer2 8MB 840MB 14inch computer3 12MB 1.6GB 17inch computer4 4MB 270MB 14inch more file2 computer1 1stfloor office5 computer3 2ndfloor office9A computer4 1stfloor office2 computer5 3rdfloor office1
If you want to merge file1 and file2, use the following command:paste file1 file2 computer1 16MB 1.2GB 17inch CDROM computer1 1stfloor office5 computer2 8MB 840MB 14inch computer3 2ndfloor office9A computer3 12MB 1.6GB 17inch computer4 1stfloor office2 computer4 4MB 270MB 14inch computer5 3rdfloor office1
The lines from file1 and file2 are separated by tab characters.
If you want to modify the default separator from the tab character to, say, / (slash), use the -d flag in the following command:paste -d"/" file1 file2 computer1 16MB 1.2GB 17inch CDROM/computer1 1stfloor office5 computer2 8MB 840MB 14inch/computer3 2ndfloor office9A computer3 12MB 1.6GB 17inch/computer4 1stfloor office2 computer4 4MB 270MB 14inch /computer5 3rdfloor office1
If you want to merge the lines from within each input file, use the -s flag in the following command:
Groupthink : Two Party System as Polyarchy : Corruption of Regulators : Bureaucracies : Understanding Micromanagers and Control Freaks : Toxic Managers : Harvard Mafia : Diplomatic Communication : Surviving a Bad Performance Review : Insufficient Retirement Funds as Immanent Problem of Neoliberal Regime : PseudoScience : Who Rules America : Neoliberalism : The Iron Law of Oligarchy : Libertarian Philosophy
War and Peace : Skeptical Finance : John Kenneth Galbraith :Talleyrand : Oscar Wilde : Otto Von Bismarck : Keynes : George Carlin : Skeptics : Propaganda : SE quotes : Language Design and Programming Quotes : Random IT-related quotes : Somerset Maugham : Marcus Aurelius : Kurt Vonnegut : Eric Hoffer : Winston Churchill : Napoleon Bonaparte : Ambrose Bierce : Bernard Shaw : Mark Twain Quotes
Vol 25, No.12 (December, 2013) Rational Fools vs. Efficient Crooks The efficient markets hypothesis : Political Skeptic Bulletin, 2013 : Unemployment Bulletin, 2010 : Vol 23, No.10 (October, 2011) An observation about corporate security departments : Slightly Skeptical Euromaydan Chronicles, June 2014 : Greenspan legacy bulletin, 2008 : Vol 25, No.10 (October, 2013) Cryptolocker Trojan (Win32/Crilock.A) : Vol 25, No.08 (August, 2013) Cloud providers as intelligence collection hubs : Financial Humor Bulletin, 2010 : Inequality Bulletin, 2009 : Financial Humor Bulletin, 2008 : Copyleft Problems Bulletin, 2004 : Financial Humor Bulletin, 2011 : Energy Bulletin, 2010 : Malware Protection Bulletin, 2010 : Vol 26, No.1 (January, 2013) Object-Oriented Cult : Political Skeptic Bulletin, 2011 : Vol 23, No.11 (November, 2011) Softpanorama classification of sysadmin horror stories : Vol 25, No.05 (May, 2013) Corporate bullshit as a communication method : Vol 25, No.06 (June, 2013) A Note on the Relationship of Brooks Law and Conway Law
Fifty glorious years (1950-2000): the triumph of the US computer engineering : Donald Knuth : TAoCP and its Influence of Computer Science : Richard Stallman : Linus Torvalds : Larry Wall : John K. Ousterhout : CTSS : Multix OS Unix History : Unix shell history : VI editor : History of pipes concept : Solaris : MS DOS : Programming Languages History : PL/1 : Simula 67 : C : History of GCC development : Scripting Languages : Perl history : OS History : Mail : DNS : SSH : CPU Instruction Sets : SPARC systems 1987-2006 : Norton Commander : Norton Utilities : Norton Ghost : Frontpage history : Malware Defense History : GNU Screen : OSS early history
The Peter Principle : Parkinson Law : 1984 : The Mythical Man-Month : How to Solve It by George Polya : The Art of Computer Programming : The Elements of Programming Style : The Unix Haterís Handbook : The Jargon file : The True Believer : Programming Pearls : The Good Soldier Svejk : The Power Elite
Most popular humor pages:
Manifest of the Softpanorama IT Slacker Society : Ten Commandments of the IT Slackers Society : Computer Humor Collection : BSD Logo Story : The Cuckoo's Egg : IT Slang : C++ Humor : ARE YOU A BBS ADDICT? : The Perl Purity Test : Object oriented programmers of all nations : Financial Humor : Financial Humor Bulletin, 2008 : Financial Humor Bulletin, 2010 : The Most Comprehensive Collection of Editor-related Humor : Programming Language Humor : Goldman Sachs related humor : Greenspan humor : C Humor : Scripting Humor : Real Programmers Humor : Web Humor : GPL-related Humor : OFM Humor : Politically Incorrect Humor : IDS Humor : "Linux Sucks" Humor : Russian Musical Humor : Best Russian Programmer Humor : Microsoft plans to buy Catholic Church : Richard Stallman Related Humor : Admin Humor : Perl-related Humor : Linus Torvalds Related humor : PseudoScience Related Humor : Networking Humor : Shell Humor : Financial Humor Bulletin, 2011 : Financial Humor Bulletin, 2012 : Financial Humor Bulletin, 2013 : Java Humor : Software Engineering Humor : Sun Solaris Related Humor : Education Humor : IBM Humor : Assembler-related Humor : VIM Humor : Computer Viruses Humor : Bright tomorrow is rescheduled to a day after tomorrow : Classic Computer Humor
The Last but not Least Technology is dominated by two types of people: those who understand what they do not manage and those who manage what they do not understand ~Archibald Putt. Ph.D
Copyright © 1996-2020 by Softpanorama Society. www.softpanorama.org was initially created as a service to the (now defunct) UN Sustainable Development Networking Programme (SDNP) without any remuneration. This document is an industrial compilation designed and created exclusively for educational use and is distributed under the Softpanorama Content License. Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.
FAIR USE NOTICE This site contains copyrighted material the use of which has not always been specifically authorized by the copyright owner. We are making such material available to advance understanding of computer science, IT technology, economic, scientific, and social issues. We believe this constitutes a 'fair use' of any such copyrighted material as provided by section 107 of the US Copyright Law according to which such material can be distributed without profit exclusively for research and educational purposes.
This is a Spartan WHYFF (We Help You For Free) site written by people for whom English is not a native language. Grammar and spelling errors should be expected. The site contain some broken links as it develops like a living tree...
|You can use PayPal to to buy a cup of coffee for authors of this site|
Last modified: March 12, 2019