Escape and combination


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Escape and combination
# 1  
Old 06-04-2010
Escape and combination

Hi

I have 2 files like:

Code:
file1
a  12
b  1
a  3

Code:
file2
a 9
c 0
a 8

and i would like to get

Code:
a 12   a 9
a 3     a 8

i can do it with grep and paste with 3 lines. I tried to combine using:
Code:
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
# 2  
Old 06-04-2010
Quote:
Originally Posted by Dedalus
...
I have 2 files like:

Code:
file1
a  12
b  1
a  3

Code:
file2
a 9
c 0
a 8

and i would like to get

Code:
a 12   a 9
a 3     a 8

...
Code:
 
paste `grep "a" file1` `grep "a" file2`

but if I do it in one step it doesn't work.
...
How about grep after the paste ?

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

tyler_durden
# 3  
Old 06-04-2010
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

Code:
$ 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

This User Gave Thanks to anbu23 For This Post:
# 4  
Old 06-04-2010
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!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Kill -9 -1 combination

Good morning, In a Production environment ive seen this command that kills processes kill -9 -1 Because i am in a production environmet i can not execute this comamnd, so i would like to know what is the difference for the conventional kill -9 PID ? Thanks a lot (11 Replies)
Discussion started by: alexcol
11 Replies

2. Shell Programming and Scripting

Combination of 6 nos

Hi folks, I have a numbers from 1-100 and from these nos I have 30 numbers.. From this 30 nos, I have to generate a combination of 6 nos... this 30 numbers will range from 1-100... ( FYI: This is not a lottery game - just kidding) ... I am trying out this in a shell script.. any ideas ? (3 Replies)
Discussion started by: gsiva
3 Replies

3. Programming

6 digits combination

Is there any program that can create 6 digit numbers with: (DIGIT_1)+(DIGIT_2)+(DIGIT_3)+(DIGIT_4)+(DIGIT_5)+(DIGIT_6)=10 Any perl or C also can. Anyone can help me? Thank you (6 Replies)
Discussion started by: Tzeronone
6 Replies

4. Shell Programming and Scripting

Auto escape script to escape special chars in script args

This is a bit off the wall, but I often need to run scripts where there are argument values that contain special characters. For example, $ ./process.exe -t M -N -o temp.mol.s -i ../molfiles/N,N\',N\'\'-trimethylbis\(hexamethylene\)triamine.mol && sfile_space_to_tab.sh temp.mol.s temp.s It... (1 Reply)
Discussion started by: LMHmedchem
1 Replies

5. Shell Programming and Scripting

help with awk for file combination

1)file1: | *Local Communication Bandwidths (MB/Sec) | Memory copy (bcopy) | | ^ | mmap_bandwidth | | ^ | mmap_read bandwidth | | ^ | memory write bandwidth | | Local Communication Latencies | Pipe Latency | 2)file2 422.6903 1948.9000 ... (9 Replies)
Discussion started by: yanglei_fage
9 Replies

6. Shell Programming and Scripting

Combination of numbers

Hello Group, I have a file of data that contain 1 2 3 4 5 I request you help with a shell script for generate all posible combination of these numbers with the following output: Example: 1 + 2 + 3 + 4 + 5 = 2 + 2 + 3 + 4 + 5 = 3 + 2 + 3 + 4 + 5 = Thanks in advance. Carlos (7 Replies)
Discussion started by: csierra
7 Replies

7. UNIX for Dummies Questions & Answers

Grep and find combination

Hello All, I'm trying the following:find . -name "*" -exec grep -ln "IsAlpha" {} \; It gives me file names only (having string "IsAlpha"), I want to get line numbers also, something like this: test 1: Line 52 test 1: Line 95 etc Is it possible to obtain using grep & find only. (5 Replies)
Discussion started by: nervous
5 Replies

8. UNIX for Dummies Questions & Answers

combination of two commands

I want to show a output like this Lee Ballancore PID TTY TIME CMD 31799 pts/3 00:00:00 vim 31866 pts/3 00:00:00 vim 2495 pts/7 00:00:00 vim 8368 pts/0 00:00:00 vim 9544 pts/2 00:00:00 ps Alistairr Rutherford PID TTY TIME CMD 8368 pts/0 00:00:00 vim 9544 pts/2 00:00:00 ps ... (3 Replies)
Discussion started by: nehaquick
3 Replies

9. UNIX for Dummies Questions & Answers

Combination Of commands

Hello All, I just wanted to know what are the different ways of using commands in combination. The most common one which i know is using pipes. Also grouping is also done like ( ls; date) where output of both the commands is displayed. Are there any other ways of combining various... (2 Replies)
Discussion started by: rahulrathod
2 Replies

10. Filesystems, Disks and Memory

Partition combination

Hi all I've got MacOSX server which is a UNIX based system. I've got 2 partiontion an I like to make just one partition on he disk without loosing any data on part1. Is there a way to do that kind of thing in UNIX or do I have to format everything and put up the system again? Thanx for reading... (3 Replies)
Discussion started by: gardarm
3 Replies
Login or Register to Ask a Question

Featured Tech Videos