LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-11-2012, 10:55 AM   #1
sawdusted
LQ Newbie
 
Registered: Dec 2012
Posts: 14

Rep: Reputation: Disabled
Nested command question


hey guys, newbie here, so pardon me for asking a basic question.

I have 2 commands that I need to run consecutive and my script writing has failed me. These are all in tab delimited files.

What I want to do:
1. Extract 5th column from fileX (cut command)
2. Compare results from extracted column with fileY (comm command)
3. Output the comparison results in fileZ

So far, this is what I have:
$ comm fileY (cut -f5 fileX) > fileZ
$ comm fileY '(cut -f5 fileX)' > fileZ
$ cut -f5 fileX | comm fileY > fileZ

I know these are all wrong. How should I write the script to do that? I have tried back-quotes and parenthesis and they all have either syntax error or claim file not found.

Last edited by sawdusted; 12-11-2012 at 10:59 AM.
 
Old 12-11-2012, 11:36 AM   #2
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,763

Rep: Reputation: 968Reputation: 968Reputation: 968Reputation: 968Reputation: 968Reputation: 968Reputation: 968Reputation: 968
You are looking for process substitution:

Code:
comm fileY <(cut -f5 fileX) > fileZ
This is bash specific, so make sure you have #!/bin/bash at the top of your script and not #!/bin/sh. Most programs use "-" as a name for stdin, so you can also do

Code:
cut -f5 fileX | comm fileY - > fileZ
That is not bash specific.

Last edited by ntubski; 12-11-2012 at 11:37 AM.
 
1 members found this post helpful.
Old 12-11-2012, 12:45 PM   #3
sawdusted
LQ Newbie
 
Registered: Dec 2012
Posts: 14

Original Poster
Rep: Reputation: Disabled
Thank you

Thanks ntubski!
 
Old 12-11-2012, 06:48 PM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 8,033

Rep: Reputation: 2146Reputation: 2146Reputation: 2146Reputation: 2146Reputation: 2146Reputation: 2146Reputation: 2146Reputation: 2146Reputation: 2146Reputation: 2146Reputation: 2146
Please mark as SOLVED once you have a working solution
 
  


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
[SOLVED] BASH Question - nested case statements jbeiter Linux - Software 2 02-13-2012 10:08 AM
[SOLVED] awk nested if, command liner patolfo Programming 37 05-14-2010 12:19 AM
Nested Threads Dralnu LQ Suggestions & Feedback 5 06-12-2006 06:25 PM
C++ nested classes enemorales Programming 5 05-23-2005 03:40 PM
c++ question about nested classes Gethyn Programming 0 08-18-2003 07:39 AM


All times are GMT -5. The time now is 08:05 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration