LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-18-2010, 09:46 PM   #1
lemon09
Member
 
Registered: Jun 2009
Location: kolkata,India
Distribution: Mandriva,openSuse,Mint,Debian
Posts: 285
Blog Entries: 1

Rep: Reputation: 37
Question 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?????

??????????????
 
Old 01-19-2010, 03:07 AM   #2
centosboy
Senior Member
 
Registered: May 2009
Location: london
Distribution: centos5
Posts: 1,137

Rep: Reputation: 116Reputation: 116
Quote:
Originally Posted by lemon09 View Post
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.
 
Old 01-19-2010, 09:11 PM   #3
lemon09
Member
 
Registered: Jun 2009
Location: kolkata,India
Distribution: Mandriva,openSuse,Mint,Debian
Posts: 285

Original Poster
Blog Entries: 1

Rep: Reputation: 37
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.
 
Old 01-19-2010, 09:22 PM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,999

Rep: Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190
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
 
Old 01-19-2010, 09:24 PM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
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"
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cant pass command line args in flwm.desktop deep_inda_jungl Ubuntu 1 05-02-2008 03:05 PM
file contents to command line args hawkmauk Linux - General 3 11-21-2006 01:27 PM
command line requires authorization with network server resnostyle Ubuntu 4 09-06-2006 09:12 PM
C command line args in linux YankeeFan Linux - Newbie 5 06-11-2006 08:22 AM
command line args in a countdown Squeak2704 Programming 1 04-26-2004 12:27 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration