Skip to main content

Questions tagged [paste]

The `paste` utility merges corresponding or subsequent lines of files.

Filter by
Sorted by
Tagged with
47 votes
10 answers
52k views

Text processing - join every two lines with commas

I have more than 1000 lines in a file. The file starts as follows (line numbers added): Station Name Station Code A N DEV NAGAR ACND ABHAIPUR AHA ABOHAR ABS ABU ROAD ABR I need to convert this to a ...
mtk's user avatar
  • 27.9k
17 votes
6 answers
13k views

A better paste command

I have the following two files ( I padded the lines with dots so every line in a file is the same width and made file1 all caps to make it more clear). contents of file1: ETIAM...... SED........ ...
Tulains Córdova's user avatar
15 votes
6 answers
10k views

Combining large amount of files

I have ±10,000 files (res.1 - res.10000) all consisting of one column, and an equal number of rows. What I want is, in essence, simple; merge all files column-wise in a new file final.res. I have ...
mats's user avatar
  • 249
14 votes
2 answers
15k views

paste files without delimiter

How do I join two files vertically without any separator? I tried to use paste -d"" a b, but this just gives me a. Sample file: 000 0 0 0 0001000200030004 10 20 30 40 2000 4000 ...
Tomas Greif's user avatar
13 votes
3 answers
18k views

paste command: setting (multiple) delimiters

In Linux, I have the following problem with paste from (GNU coreutils) 8.13: Trying to set another delimiter than the default (TAB) results in either just printing the first character of the defined ...
erch's user avatar
  • 5,090
12 votes
4 answers
9k views

How to interleave the lines of two or more files?

I have tried to get the 2 files output in a single file. I have tried below command: cat file1 file2 but here file2 data is appending to file1. What I need is file1 1st line followed by file2 ...
user73553's user avatar
  • 365
12 votes
2 answers
9k views

How to copy text from command line to clipboard without using the mouse?

I'm trying to figure out a way to copy the current text in a command line to the clipboard WITHOUT touching the mouse. In other words, I need to select the text with the keyboard only. I found a half-...
Sancho Pancho's user avatar
9 votes
5 answers
12k views

Merge alternate lines from two files

File1: .tid.setnr := 1123 .tid.setnr := 3345 .tid.setnr := 5431 .tid.setnr := 89323 File2: .tid.info := 12 .tid.info := 3 .tid.info := 44 .tid.info := 60 Output file: .tid.info := 12 .tid.setnr ...
Nainita's user avatar
  • 2,922
9 votes
7 answers
5k views

How can I apply `cut` to several files and then `paste` the results?

I often do operations like paste <(cut -d, -f1 file1.csv) <(cut -d, -f1 file2.csv) which is very tedious with more than a few files. Can I automate this process, e.g. with globbing? I can ...
shadowtalker's user avatar
  • 1,358
9 votes
1 answer
6k views

How to merge two files in corresponding row?

Now,I have two files: aaaa.txt: a=0; b=1; c=2; bbbb.txt: d=3 e=4 f=5 I want to merge aaaa.txt and bbbb.txt to cccc.txt. cccc.txt as follow: a=0;d=3 b=1;e=4 c=2;f=5 So, what can I do for this?
binghenzq's user avatar
  • 581
8 votes
2 answers
7k views

How to paste output of multiple commands

I want to merge two unzipped files f1 and f2 in one command, like paste (zcat f1.gz) (zcat f2.gz). What is the right syntax?
user196711's user avatar
8 votes
4 answers
4k views

Is there a command can do the reverse of what the paste command does?

The paste command can merge multiple lines into one. For example, if I have a file test.txt and it contains: original text a aa aaa b bb bbb c cc ccc I can use the command paste -s -d '\t\t\n' test....
Just a learner's user avatar
8 votes
2 answers
20k views

Select certain column of each file, paste to a new file

I have 20 tab delimited files with the same number of rows. I want to select every 4th column of each file, pasted together to a new file. In the end, the new file will have 20 columns with each ...
Jun Cheng's user avatar
  • 105
8 votes
1 answer
21k views

How to merge text file vertically? [duplicate]

Let's assume that I've got two text file a, b. $cat a a a a a a a $cat b b b b b b b Then, I want to merge these two file vertically by using paste. The merged file is shown bellow a a a a a a b b ...
comphys's user avatar
  • 319
7 votes
4 answers
13k views

Print two files in two columns side-by-side

I want to output two text files in two columns — one on the left side and other one on the right. paste doesn't solve the problem, because it only insert a character as delimiter, so if the first file ...
belkka's user avatar
  • 483
7 votes
5 answers
686 views

How to make `paste` command stop on shortest file

I have two files: a.txt 1 2 3 b.txt foo bar baz qux Running paste a.txt b.txt gives 1 foo 2 bar 3 baz qux However I want to stop when the shortest file ends (that is, I want to print only ...
user1350864's user avatar
7 votes
1 answer
955 views

What is the correct way to merge two ASCII art files side by side while preserving alignment?

art_file (cat -A output): .::""-, .::""-.$ /:: \ /:: \$ |:: | _..--""""--.._ |:: |$ '\:.__ / .' ...
puwlah's user avatar
  • 519
6 votes
4 answers
3k views

How to print multi-line variables in side-by-side columns in sh?

This question is based on a similar question on Ask Ubuntu, but instead of bash, I would like to have similar output in sh. No issue in bash; it works as expected. wolf@linux:~$ echo $SHELL /usr/bin/...
Wolf's user avatar
  • 1,671
5 votes
3 answers
2k views

How to merge the different lines of files?

What is the fastest command line way to merge the different lines of files? For example, I have two files: a.txt: foo bar foobar b.txt foo foobar line by bar And I would like to get the ...
kbenda's user avatar
  • 153
5 votes
3 answers
1k views

Rounding many values in a csv to 3 decimals (printf ?)

I have a paste command like this paste -d , file1.csv file2.csv file3.csv And file2.csv contains numbers like this 0.2 0.3339 0.111111 I want the values in file2.csv having 3 decimals like this: 0....
R 9000's user avatar
  • 167
5 votes
3 answers
353 views

Merging files based on potentially incomplete keys

I want to merge two files like How to merge two files based on the matching of two columns? but one file may not have all results. So for example file1 1 dog 2 cat 3 fox 4 cow file2 1 woof 2 meow 4 ...
sadfasdfasdfddd's user avatar
5 votes
5 answers
8k views

Trying to add a newline to the paste command

Here is the weak attempt at a paste command trying to include a newline: paste -d -s tmp1 tmp2 \n tmp3 \n tmp4 tmp5 tmp6 > tmp7 Basically I have several lines in each tmp and I want the ...
user3347022's user avatar
5 votes
4 answers
253 views

Build table - Add column depending on filenames

I have a huge amount of files having the following naming style: WBM_MIROC_rcp8p5_mississippi.txt WBM_GFDL_rcp8p5_nosoc_mississippi.txt DBH_HADGEM_rcp4p5_co2_mississippi.txt ...
steve's user avatar
  • 548
5 votes
3 answers
2k views

UNIX paste columns and insert zeros for all missing values

I would like to merge specific columns from two txt files containing varying number of rows, but same number of columns (as shown below): file1: xyz desc1 12 uvw desc2 55 pqr desc3 ...
biobudhan's user avatar
  • 547
5 votes
5 answers
3k views

Replace data at specific positions in txt file using data from another file

I have a text file in the below format: $data This is the experimental data good data This is good file datafile 1 4324 3673 6.2e+11 7687 67576 2 3565 8768 8760 5780 8778 "This is line '...
Nilesh's user avatar
  • 301
4 votes
6 answers
2k views

Concatenate multiple files with two blank lines as delimiter?

I'm trying to join Markdown files with two newlines between each file. I've tried using the following command: paste -sd '\n\n' file1.md file2.md This joins the files with a newline, but not two ...
Naftuli Kay's user avatar
  • 40.4k
4 votes
4 answers
4k views

Combine list of words into one line, then add characters

I want to take a file that has a list of words on each line of its own eg. act bat cat dog eel and put them into one line with comma separated and quoting them. So that it turns out like: 'act', '...
sh_newbie's user avatar
4 votes
1 answer
694 views

Problem with paste and standard output in linux

I have two files that I am trying to merge, one file is: linux$ cat temp2 linear_0_A_B linear_0_B_A 103027.244444 102714.177778 103464.311111 102876.266667 103687.422222 103072.711111 103533.244444 ...
asm_nerd1's user avatar
  • 195
4 votes
1 answer
16k views

Cut and Paste Commands

So I have: $ cat fruits 2 bananas 3 cherries 4 figs 5 dates 6 elderberries 7 apples 8 grapes and 1 $ cat prices 2 2.18 3 4.11 4 1.69 5 4.52 6 1.73 7 1.01 8 1.09 Every line from 'fruits' ...
Highlights Factory's user avatar
4 votes
1 answer
336 views

Use paste with row-major input

I can create a file with multiple columns from a single-column input via paste like this: some_command | paste - - This works when some_command produces the data in column-major format. In other ...
Konrad Rudolph's user avatar
4 votes
3 answers
824 views

Fast version of paste

paste is a brilliant tool, but it is dead slow: I get around 50 MB/s on my server when running: paste -d, file1 file2 ... file10000 | pv >/dev/null paste is using 100% CPU according to top, so it ...
Ole Tange's user avatar
  • 36k
4 votes
1 answer
3k views

Loop through files and join horizontally

I am trying to do the following: Loop through a list of files Edit each file and output a "trimmed" file Horizontally join each trimmed file in turn to a pre-made master file I have steps 1 & 2 ...
Gaius Augustus's user avatar
4 votes
2 answers
547 views

How do I append text from one line, to the end of another?

The original output file contained this block of text among much more information: Projecting out rotations and translations Force Constants (Second Derivatives of the Energy) in [a.u.] ...
Stephen Mason's user avatar
4 votes
2 answers
2k views

How to use Ctrl+mouse click in tmux?

Due to the change in Tmux2.1, I need to remap my mouse's middle click to tmux's paste: bind -T root MouseDown2Pane run -b "tmux paste-buffer" However, I also would like to enable using Ctrl (or Alt, ...
dragonxlwang's user avatar
3 votes
3 answers
693 views

How to parse input file once and send to two separate streams and display side-by-side?

I've got the following script: #!/usr/bin/env bash # Script to generate MD5 hash for each line. [ $# -eq 0 ] && { echo "Usage: $0 file"; exit 1; } file=$1 shopt -s expand_aliases alias ...
kenorb's user avatar
  • 21.5k
3 votes
3 answers
881 views

Intersperse lines from two files

I have a data file ($file1) which contains two lines of data per individual. I need to intersperse a third line of data from another data file ($file2). So my input looks like: >cat $file1 bob ...
Simon O'Hanlon's user avatar
3 votes
3 answers
2k views

How to print the second column of many files?

I have more than 10 files, the 1st column is the same in all files, I need to collect all the columns 2 in all files against the 1st column in one file. I tried with paste then awk but this print only ...
Mohsen El-Tahawy's user avatar
3 votes
2 answers
939 views

Merge and Append columns for more than 2 files

The files are tab separated. I have "N" number of files whose contents are as shown in the screenshot above. I want to merge them and append the 5th column. The first 4 columns are the same. I tried ...
Kiran's user avatar
  • 31
3 votes
1 answer
1k views

Trouble with horizontial merge of csv files under Cygwin

I have two csv files: test1.csv 1 2 3 4 test2.csv 6 7 8 9 I want to horizontally merge these two files. To do this I use paste -d , test1.csv test2.csv > paste.csv If I open this file in ...
Jacob H's user avatar
  • 133
3 votes
3 answers
3k views

how can I slow down pasting text into a serial terminal?

I'm working on a raspberry pi, and trying to paste some text files into a command-line text editor nano... but the text ends up corrupted on the remote end (partial/incomplete text). I can only guess ...
nmz787's user avatar
  • 190
3 votes
1 answer
924 views

Command to "fill down" columns in text file, a la the Excel fill down function

I have a text file with rows, and columns within those rows. I want to, essentially, replicate the Excel "fill down" function. In other words, if there is a blank "cell" on a line, it will look to the ...
Simonmdr's user avatar
  • 141
3 votes
1 answer
401 views

can't copy screenshot in KDE/Debian 10

I have Debian 10 with KDE. Everything was working fine and suddenly today when I tried to copy a screenshot it didn't work. When I press the printscreen key, I get the popup showing the screenshot ...
raphael75's user avatar
  • 743
3 votes
3 answers
229 views

regex from two files

I have two files that built of blocks of 4 lines, starting with a @. They are matching and in order. The files are too big (>10 GB) so I am putting here the first 3 blocks of each (12 lines). 1st: ...
Hassan Massalha's user avatar
2 votes
4 answers
170 views

Concatenate different fields with different seperator

I have a tab delimited file like this: chr1 53736473 54175786 chr1 56861276 56876438 chr1 57512145 57512200 I want to concatenate the three fields result like this: ...
Jun Cheng's user avatar
  • 105
2 votes
3 answers
717 views

Paste all files in directory column-wise by last modification order

I am looking to combine all files in a directory (each having one column) into a single file with multiple columns. However, I need the files to be pasted by last modification time order, i.e. in the ...
MSR's user avatar
  • 21
2 votes
3 answers
1k views

Format output file from paste command

I have two or more files FileA A: 18.49 RPKM C: 14.49 RPKM B: 18.89 RPKM FileB A: 21.29 RPKM C: 38.71 RPKM B: 36.13 RPKM I want to paste these two files and print first-column ...
CN_229133's user avatar
  • 115
2 votes
3 answers
1k views

Why can't `paste` print stdin next to stderr?

Usually paste prints two named (or equivalent) files in adjacent columns like this: paste <(printf '%s\n' a b) <(seq 2) Output: a 1 b 2 But when the two files are /dev/stdin and /dev/...
agc's user avatar
  • 7,273
2 votes
3 answers
417 views

How do I add numbers from two txt files and write it to the same file?

I want to add numbers from two txt files. The number will change in file1, and file2 should update itself like this file2 = file1 + file2. Decimals not needed. Example: file1 3 file2 7 Output: ...
machinecat's user avatar
2 votes
3 answers
51 views

How to collect both full lines, and matching part of line?

Is it possible to output both the full line and the matched parts of some line? Suppose I have this input low [ 0]: 0xffff0000 Interesting description A hi [ 0]: 0xffff00a0 Interesting description B ...
Moberg's user avatar
  • 187
2 votes
1 answer
433 views

Why does paste command truncate one of the input files?

I have two files which contain only one column of numeric data each, and the same number of rows. When using paste, it does combine the rows from the two files into one row, but the text of the first ...
golimar's user avatar
  • 427