Proper way to pipe into awk command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Proper way to pipe into awk command
# 1  
Old 10-20-2015
Proper way to pipe into awk command

What is the proper way to run two commands together?

For example, in the below I would like run a command in bold then pipe that output to awk to re-format it. Thank you Smilie.

Code:
bedtools nuc -fi /home/cmccabe/Desktop/bed/hg19.fa -bed /home/cmccabe/Desktop/bed/xgen_baits.bed > /home/cmccabe/Desktop/bed/xgen_GC_baits.bed | awk 'NR>1 {print $1, $2, $3, $4, $6, $8}' OFS="\t" xgen_GC_baits.bed > GC.bed

# 2  
Old 10-20-2015
Code:
command1 > tmp1
command2 < tmp1 > final.output

is functionally identical with
Code:
command1 | command2 > final.output

(and you don't need the tmp1 file)
awk can directly open a file if passed as an additional parameter. Do not pass one, and it reads from stdin (standard input).
Code:
bedtools nuc -fi /home/cmccabe/Desktop/bed/hg19.fa -bed /home/cmccabe/Desktop/bed/xgen_baits.bed |
 awk 'NR>1 {print $1, $2, $3, $4, $6, $8}' OFS="\t" > GC.bed

This User Gave Thanks to MadeInGermany For This Post:
# 3  
Old 10-20-2015
You can use stdout only once - either redirect to a file with > or pipe it to another command with | .
Should you REALLY need both, there's an equivalent to a plumber's T-fitting or T-piece: tee (surprise!). Use like cmd1 | tee outfile1 outfile2 ... | cmd2 > resfile1
This User Gave Thanks to RudiC For This Post:
# 4  
Old 10-20-2015
Thank you both Smilie.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Proper Use of WAIT Command Within .ksh

I am trying to write a korn shell script (Z.ksh) that will execute three other korn shell scripts within it. The three korn shell scripts (A.ksh,B.ksh,C.ksh) each execute a series of .sas programs. A.ksh, B.ksh, and C.ksh must each wait until the last .sas program within them executes and finishes... (2 Replies)
Discussion started by: imoore
2 Replies

2. UNIX for Beginners Questions & Answers

awk command to split pipe delimited file

Hello, I need to split a pipe de-limited file based on the COLUMN 7 value . If the column value changes I need to split the file Source File Payment|ID|DATE|TIME|CONTROLNUMBER|NUMBER|NAME|INDICATOR 42156974|1137937|10/1/2018|104440|4232|2054391|CARE|1... (9 Replies)
Discussion started by: rosebud123
9 Replies

3. Shell Programming and Scripting

Using awk to place decimal points at proper position

Hi, I have one input file which is delimited by pipe. I want to put decimal points in this input file at particular position in particular column and also get the negative sign (if any) at start of that column. $ cat Input_file.txt 11|10102693|1|20151202|10263204|20151127|N|0001... (7 Replies)
Discussion started by: Prathmesh
7 Replies

4. Shell Programming and Scripting

Awk - Summation in Proper decimal Format

Hi I am executing below command to do summation on 46th coloumn. cat File1| awk -F"|" '{p += $46} END { printf"Column Name | SUM | " p}' I am getting output as Column Name | SUM | 1.01139e+10 Here I want output in Proper decimal format. Can someone tell me what change is required for same? (1 Reply)
Discussion started by: sanranad
1 Replies

5. Shell Programming and Scripting

Extract all proper names from string with awk

I want to extract the proper names with awk from a very long string, like: õ(k): &lt;/span&gt;<br /><a something="pls/pe/person.person?i_pers_id=3694&amp;i_topic_id=2&amp;i_city_id=3372&amp;i_county_id=-1" target="_blank"><b>Gary Oldman</b></a> (George Smiley)<br /><a... (12 Replies)
Discussion started by: lyp
12 Replies

6. Shell Programming and Scripting

pipe in command

Hello, I try to concatenate a command to execute. Sadly it throws an error. #!/bin/bash cd / cmd="find -name *.txt | awk '{ printf "FILE: "$1; system("less "$1);}' | egrep 'FILE:|$1'" echo "1." $($cmd) echo "2." $("$cmd") echo "3." `$cmd` echo "4." `"$cmd"`1.&3. 'find: paths must... (2 Replies)
Discussion started by: daWonderer
2 Replies

7. Shell Programming and Scripting

Net::SSH::Perl->Execute any unix command & display the output in a proper form

Net::SSH::Perl ...... how to print the output in a proper format my $cmd = "ls -l"; my $ssh = Net::SSH::Perl->new($host); $ssh->login($user, $pass); my($stdout, $stderr, $exit) = $ssh->cmd("$cmd"); print $stdout; the script works fine, but i am unable to see the output... (2 Replies)
Discussion started by: gsprasanna
2 Replies

8. BSD

proper syntax of grep command

I'm learning UNIX on my mac (BSD), using a manual. I'm trying to figure out the grep command, and am getting something wrong. I've opened one of my files in NeoOffice and am looking for a string, the phrase 'I am writing.' I've been to some sites to get the proper syntax, and from what I can see... (5 Replies)
Discussion started by: Straitsfan
5 Replies

9. Shell Programming and Scripting

Is it better to grep and pipe to awk, or to seach with awk itself

This may just be a lack of experience talking, but I always assumed that when possible it was better to use a commands built in abilities rather than to pipe to a bunch of commands. I wrote a (very simple) script a while back that was meant to pull out a certain error code, and report back what... (4 Replies)
Discussion started by: DeCoTwc
4 Replies

10. UNIX for Dummies Questions & Answers

How can I use pipe command ?

Hi My friends I have used this command to find files are modified within the past 24 hours and then many files are shown but I want transfer all these files to special directory by using pipe . can any one tell me what is the next step ? (11 Replies)
Discussion started by: bintaleb
11 Replies
Login or Register to Ask a Question