I am using a paste command to concatenate two .csv files column wise. These both files are huge file and when I run the paste command as below where comma(,) is the delimiter:

paste -d',' file1.csv file2.csv > file3.csv

The command fails giving output

paste: line too long

However, I searched the same over internet and in paste command's manual also. I found the below diagnostics.

"line too long"         Output lines are restricted  to  511

Is there any alternate way to obtain the result, then?

I am using below version of bash:

GNU bash, version 3.2.57(1)-release (sparc-sun-solaris2.10)

try this command

nawk '{if ((getline a < "-") > 0) $0 = $0 "," a; print}' file1.csv < file2.csv > file3.csv

this command will browse your file1.csv and file2.csv line by line and save the line from the file1.csv in $0 (for nawk $0 match the hole line, $1 the first column, $2 the second...) and save the line from file2.csv in the variable a. After that it will print $0 (the line from file1), then "," then a (the line from file2) in the file3.csv

| improve this answer | |
  • OP needs a , separator between lines from the two files – iruvar Dec 27 '16 at 13:26
  • Thanks @Dababi The files get concatenated within no time but without delimiter. I want to put ',' comma while concatenating the files. Also can you explain the command line, what is the use of '-', $0 = $0, a. – tpsaitwal Dec 28 '16 at 7:14
  • I update the command, it will work as expected. Try it and give me the result – Dababi Dec 28 '16 at 7:59
  • @Dababi thanks the solution and its explanation. It is completely working fine. – tpsaitwal Dec 29 '16 at 8:15

Redirect the file to a new filehandle and read from it while reading from input:

#! /bin/bash
exec 3< file1
while read -r two ; do
    read -r -u3 one
    echo "$one,$two"
done < file2
| improve this answer | |
  • you mind explaining what this will do , Please. – rɑːdʒɑ Dec 27 '16 at 10:58
  • It redirects file1 to filehandle 3, then reads file2 line by line, reading one line from fh 3 at the same time, and outputting both values read from the files. – choroba Dec 27 '16 at 19:26

The problem is that the tools provided by Solaris are inferior to GNU tools. You should install them, if possible. If not, there might be a better paste in xpg4.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.