Escape and combination

Hi

I have 2 files like:

file1
a  12
b  1
a  3
file2
a 9
c 0
a 8

and i would like to get

a 12   a 9
a 3     a 8

i can do it with grep and paste with 3 lines. I tried to combine using:

paste `grep "a" file1` `grep "a" file2`

but if I do it in one step it doesn't work.
Maybe the problem is the escape char ?
Any idea?
Thanks
D

How about grep after the paste ?

$
$ paste file1 file2 | grep ^a
a  12   a 9
a  3    a 8
$
$

tyler_durden

paste is expecting filename and not the contents of a file. You can use awk command and remove any lines which dont have "a" and then use paste command

$ cat file1
a  12
b  1
a  3
$ cat file2
a 9
c 0
a 8
$ awk ' /a/ { print > FILENAME } ' file1 file2 && paste file1 file2
a  12   a 9
a  3    a 8
$ cat file1
a  12
a  3
$ cat file2
a 9
a 8
1 Like

Thanks both

now I understood. The problem for me was to understand why it doesn't work and anbu23 you're right I should give to paste the name of a file and not the parsed content.
great!