Pipe awk's output to sed for deletion


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pipe awk's output to sed for deletion
# 1  
Old 10-22-2012
Pipe awk's output to sed for deletion

Hi Friends,

I am using a command that prints certain lines from a file.

For ex:

cat input

Code:
abc chr1 456
def chr1 789
ghi chr1 999
jjj chr1 777
jhk chr7 914

My command

Code:
awk '{if($2=="chr1" && $3>=456 && $3<=999) {print $0}}' OFS="\t" input

Output being printed is
Code:
abc chr1 456
def chr1 789
ghi chr1 999

I want to pipe this output to sed or whatever to delete these lines. Maybe like this

Code:
awk '{if($2=="chr1" && $3>=456 && $3<=999) {print $0}}' OFS="\t" input | sed '/d/' 

My final required input file should be

Code:
jjj chr1 777
jhk chr7 914

I don't want to try it for myself because it is a huge 27GB input file. Any mistakes will cost me money and time to regenerate it.
# 2  
Old 10-22-2012
I'd strongly suggest you try your OWN implementation on a smaller sample and work out the 'kinks' yourself - it should be pretty simple given you already have a good start that you presumably understand.
Not trying it yourself will cost you knowledge in the long run.
Good luck and do come back if/when you get stuck.
This User Gave Thanks to vgersh99 For This Post:
# 3  
Old 10-22-2012
Your awk logic doesnt make any sense to me...
# 4  
Old 10-22-2012
your requirement is going nowhere...or am not understanding...
# 5  
Old 10-22-2012
The OP needs to reverse the original awk logic - the implementation is left as an exercise.
This User Gave Thanks to vgersh99 For This Post:
# 6  
Old 10-22-2012
Quote:
Originally Posted by vgersh99
The OP needs to reverse the original awk logic - the implementation is left as an exercise.
Hi vgersh99,

But, how do I feed the awk's output to sed? It is giving me the following error when I pipe to
Code:
sed '/d'

Code:
sed: -e expression #1, char 3: missing command

and then I used -e and still it gives the same error.

---------- Post updated at 03:36 PM ---------- Previous update was at 03:24 PM ----------

Okay. Thanks for the suggestions.

I now understood what needs to be done.

So, what I did was this

Code:
awk '{if($2=="chr1" && $3>=456 && $3<=999) {print $0}}' OFS="\t" input > intermediate_input

Code:
join -v1 -v2 input intermediate_input > final_input

But, there is a small glitch here. I am missing the immediate next line after the last line in intermediate_input.

Which means, instead of

Code:
jjj chr1 777
jhk chr7 914

I am seeing

Code:
jhk chr7 914

Any thoughts?

Alos, please suggest a pointer to keep the input file and the final_input file's pattern or separators to be the same. They changed completely after running the above command.
# 7  
Old 10-22-2012
you don't need anything other than awk:
Code:
awk '!($2=="chr1" && $3>=456 && $3<=999)' OFS='\t' myFile

In your desired output"
Code:
jjj chr1 777
jhk chr7 914

why do you need the line in red? This is not what you coded...
This User Gave Thanks to vgersh99 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pipe or combine output of three awk commands

What is the correct syntax to pipe or run three awk commands? Basically, using the output of the first awk as input in the second. Then using the output of the second awk in the third. Thank you :). awk 'FNR==NR {E; next }$3 in E {print $3, $5}' panel_genes.txt RefSeqGene.txt > update.txt |... (3 Replies)
Discussion started by: cmccabe
3 Replies

2. Shell Programming and Scripting

sed command to replace a line in a file using line number from the output of a pipe.

Sed command to replace a line in a file using line number from the output of a pipe. Is it possible to replace a whole line piped from someother command into a file at paritcular line... here is some basic execution flow.. the line number is 412 lineNo=412 Now i have a line... (1 Reply)
Discussion started by: vivek d r
1 Replies

3. Shell Programming and Scripting

Insert a value in a pipe delimited line (unsig sed,awk)

Hi, I want to insert a value (x) in the 3rd position of each line in a file like below a|b|c|d|1 a|b|c|d a|b|c|d|e|1 a|b|cso that output file looks like a|b|x|c|d|1 a|b|x|c|d a|b|x|c|d|e|1 a|b|x|cI can do that using perl as below #!/usr/bin/perl -w use strict; #inserting x at... (5 Replies)
Discussion started by: sam05121988
5 Replies

4. Shell Programming and Scripting

Problem with output awk and sed

I have file, i am extracting email address from file. but problem is that output is very ugly. I am using this command REMOVED "CSS OFFENDING CODE"... While original filename have no such character. Please suggest. (20 Replies)
Discussion started by: learnbash
20 Replies

5. Shell Programming and Scripting

Use less pipe for grep or awk sed to print the line not include xx yy zz

cat file |grep -v "xx" | grep -v "yy" |grep -v "zz" (3 Replies)
Discussion started by: yanglei_fage
3 Replies

6. UNIX for Dummies Questions & Answers

sed - combination of line deletion and pattern matching

I want to delete all the blank lines from a file before a certain line number. e.g. Input file (n: denotes line number) 1: a 2: 3: b 4: c 5: 6: d I want to delete all blank lines before line number 3, such that my output is: a b c d I see that sed '/^$/d' in_file works... (9 Replies)
Discussion started by: jawsnnn
9 Replies

7. UNIX for Dummies Questions & Answers

Use awk to pipe output from one file into multiple files

Hi All. Thanks for your help in advance. I have a requirement to examine the number of delimiters in each record of a file. If the record has the expected number of delimiters it should be passed into a 'good' file. If it does not, the record should be passed into a 'bad' file. I have been able... (8 Replies)
Discussion started by: codestar1
8 Replies

8. Shell Programming and Scripting

help with sed or awk with less pipe

<tr><th align=right valign=top>Faulty_Part</th><td align=left valign=top>readhat version 6.0</td></tr> <tr><th align=right valign=top>Submit_Date</th><td align=left valign=top>2011-04-28 02:08:02</td></tr> .......(a long string) I want to get all the field between "left valign=top>" and "... (2 Replies)
Discussion started by: yanglei_fage
2 Replies

9. Shell Programming and Scripting

pipe'ing grep output to awk

This script is supposed to find out if tomcat is running or not. #!/bin/sh if netstat -a | grep `grep ${1}: /tomcat/bases | awk -F: '{print $3}'` > /dev/null then echo Tomcat for $1 running else echo Tomcat for $1 NOT running fi the /tomcat/bases is a file that... (2 Replies)
Discussion started by: ziggy25
2 Replies

10. Shell Programming and Scripting

pipe output of grep to sed?

Is there a way I can do this: search for text and replace line containing matched text with a different line? For example: "I want to replace text" I want to search for replace and then change the line to I am perplexed. Hope that makes sense. Thanks in advance. (4 Replies)
Discussion started by: arsh
4 Replies
Login or Register to Ask a Question