Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 12-11-2012, 11:55 AM   #1
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 11:59 AM.
Old 12-11-2012, 12:36 PM   #2
Senior Member
Registered: Nov 2005
Distribution: Arch
Posts: 3,061

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

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

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

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

Original Poster
Rep: Reputation: Disabled
Thank you

Thanks ntubski!
Old 12-11-2012, 07:48 PM   #4
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,425

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


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 11:08 AM
[SOLVED] awk nested if, command liner patolfo Programming 37 05-14-2010 01:19 AM
Nested Threads Dralnu LQ Suggestions & Feedback 5 06-12-2006 07:25 PM
C++ nested classes enemorales Programming 5 05-23-2005 04:40 PM
c++ question about nested classes Gethyn Programming 0 08-18-2003 08:39 AM

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

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