LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   how to pipeline when the file requires two command line args???? (https://www.linuxquestions.org/questions/programming-9/how-to-pipeline-when-the-file-requires-two-command-line-args-783112/)

lemon09 01-18-2010 09:46 PM

how to pipeline when the file requires two command line args????
 
Hiiiiiii!!!!!!!!!

Suppose that there are two files
Code:

$ cat abc1
a1      a2
b1      b2
c1      c2

$ cat abc2
x1      x2
y1      y2
z1      z2

Now suppose I want to view side by side both the files but only the first field should appear. Following is the desired output:
Code:

x1      a1
y1      b1
z1      c1

I could probably use the 'cut' command to filter out the fields but how do send these two files to the 'paste' command.

Any other way to achieve the goal?????

??????????????

centosboy 01-19-2010 03:07 AM

Quote:

Originally Posted by lemon09 (Post 3831628)
Hiiiiiii!!!!!!!!!

Suppose that there are two files
Code:

$ cat abc1
a1      a2
b1      b2
c1      c2

$ cat abc2
x1      x2
y1      y2
z1      z2

Now suppose I want to view side by side both the files but only the first field should appear. Following is the desired output:
Code:

x1      a1
y1      b1
z1      c1

I could probably use the 'cut' command to filter out the fields but how do send these two files to the 'paste' command.

Any other way to achieve the goal?????

??????????????


Code:

paste file1 file2
There are numerous ways to do this, but i wouldnt want to waste time trying to figure out options for join, cut etc etc.

A quick way would be to pipe the paste command to awk maybe??

Code:

paste abc1 abc2 | awk '{print $3, $1}'
Not sure if this is the answer you are looking for, but that is how i would do it.

lemon09 01-19-2010 09:11 PM

Thanks!!!!!

Now I have one more question.
Suppose that I have a file named student.txt
Code:

$ cat student.txt
180 : Tridip Neogi : 234
190 : John Karl    : 424
160 : kartugi Pagi : 334

The first field is the roll no, second the name and in the last is the marks obtained by them. If suppose I want to search for a specific roll no. and then display the whole line----How shall I do that.
Look I just can't use grep because the roll no and the marks may be same. I have to cut it vertically. and then how shall I print the matching line.

grail 01-19-2010 09:22 PM

Wouldn't be too quick to cast grep aside as there are plenty of regex options to help you.

How about: grep "^180" student.txt

This will return all lines that start ('^' is start of line) with number 180

pixellany 01-19-2010 09:24 PM

What book or tutorial are you using?

You can use--as a minimum--GREP OR SED. In either case, you want to search for the number at the beginning of the line---all you have to do is add the character for "beginning of line"---"^"

example:

Code:

sed -n '/^the/p' filename
returns all lines beginning with "the"


All times are GMT -5. The time now is 05:07 AM.