paste command is used to add columns:
$ wc -l <data1 | paste -d, file -
This is literally what you asked for; the output of
wc is added to the end of the line of the file. The output of
wc has whitespace at the start of the line, which is why you get the spacing you get here.
To remove this whitespace:
$ wc -l <data1 | sed 's/^ *//' | paste -d, file -
paste command is here used with
-d, which makes it insert a comma between the old and the new columns. The
- signals that the new columns should be read from standard input rather than from a file. The standard input comes from
wc -l which counts the number of lines in the file.
The variation with
sed simply takes the
wc output and removes any space characters at the start of the line.
bash process substitution:
paste -d, file <( wc -l <data1 | sed 's/^ *//' )
Here, the process substitution,
<( ... ), takes the place of