Sponsored Content
Top Forums Shell Programming and Scripting Replace a column with a value conditional on a value in col1 Post 302374776 by genehunter on Wednesday 25th of November 2009 12:08:15 PM
Old 11-25-2009
Replace a column with a value conditional on a value in col1

Hi,
Perhaps a rather simple problem...?
I have data that looks like this.
Code:
BPC0013 ANNUL_49610 0 0 1 1
BPC0014 ANNUL_49642 0 0 2 1
BPC0015 ANNUL_49580 0 0 1 1
BPC0016 ANNUL_49596 0 0 2 1
BPC0017 VULGO_49612 0 0 1 1
BPC0018 ANNUL_49628 0 0 1 1
BPC0019 ANNUL_49692 0 0 2 1
170291_HMG ANNUL_170291 0 0 1 1
170351_HMG ANNUL_170351 0 0 1 1
170475_HMG 170475 0 0 2 1
170497_HMG ANNUL_170497 0 0 2 1
170534_HMG ANNUL_170534 0 0 1 1
170559_HMG ANNUL_170559 0 0 1 1

I want to change the col6 value to 2 only if the line does not start with BPC.
Code:
awk -F "\t" '{if($1==BPC) {print $1,$2,$3,$4,$5,$6} else{print $1, $2, $3, $4, $5, $6="2"}} ' testfam.fam > atestedfam.fam

I tried this, but it is changing everything to 2 at col6.

Last edited by genehunter; 11-25-2009 at 01:30 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed conditional string replace for each line

Hi all, I appreciate the enormous amount of knowledge that flows in this forum. I am an average UNIX user. I have many files with lines like the below. I have separated each line with space for ease of reading. I need to replace the first occurance of "/00" with null on those lines that have... (6 Replies)
Discussion started by: Nanu_Manju
6 Replies

2. Shell Programming and Scripting

awk help to do conditional find and replace

Hi, I have a Line input for awk as follows DROP MATERIALIZED VIEW MCR.COMM_STACK; CREATE MATERIALIZED VIEW "MCR"."COMM_STACK" ON PREBUILT TABLE WITHOUT REDUCED PRECISION USING INDEX REFRESH FAST ON DEMAND START WITH sysdate+0 NEXT SYSDATE + 7 WITH PRIMARY KEY USING DEFAULT... (3 Replies)
Discussion started by: rajan_san
3 Replies

3. Shell Programming and Scripting

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2 file 1 sample SNDK 80004C101 AT XLNX 983919101 BB NETL 64118B100 BS AMD 007903107 CC KLAC 482480100 DC TER 880770102 KATS ATHR 04743P108 KATS... (7 Replies)
Discussion started by: rydz00
7 Replies

4. Shell Programming and Scripting

Sed conditional replace

Given this row: |lastname1|middlename1|firstname1|lastname2|middlename2|firstname2 produce this result: |lastname|middlename|firstname where the resultant names are based on the presence of the #2 names above. I.e., if a #2 name is passed (usually will be null,) use that - otherwise... (8 Replies)
Discussion started by: tiggyboo
8 Replies

5. Programming

Conditional replace after reading in a file

I need to read the contents of a file. Then I need to grep for a keyword and replace part of the grepped line based on the condition of previous and present line. Example input file: V { port1 = P; port2 = 0; shift_port = P0; /* if next shift_port is P0 I need... (7 Replies)
Discussion started by: naveen@
7 Replies

6. Shell Programming and Scripting

Conditional Search/Replace

I'm looking for an awk or (preferably) sed solution to search a pipe delimited file for any occurrence of an email address that does not include a designed domain, and replace the email address with a blank. E.g. hello|smith@designateddomain.com|jones@anotherdomain.edu|1234| turns into: ... (2 Replies)
Discussion started by: tiggyboo
2 Replies

7. UNIX for Dummies Questions & Answers

If col1 and col2 of any line in both of two files in two files match, col1 and col2

I have two files, and I'm interested in the first two columns of each. File1 compares set1 to set2 (column1 = set1 name, column2 = set2 name). File2 compares set2 to set1 (column1 = set2 name, column2 =set1 name). I want to print the set names (column values) that appear as pairs in both... (1 Reply)
Discussion started by: pathunkathunk
1 Replies

8. Shell Programming and Scripting

sed conditional \n replace for each line

How could be removed \n only if appearing at position 80 in the line? (4 Replies)
Discussion started by: RomanF
4 Replies

9. Shell Programming and Scripting

Filter on one column and then perform conditional calculations on another column with a Linux script

Hi, I have a file (stats.txt) with columns like in the example below. Destination IP address, timestamp, TCP packet sequence number and packet length. destIP time seqNo packetLength 1.2.3.4 0.01 123 500 1.2.3.5 0.03 44 1500 1.3.2.5 0.08 44 1500 1.2.3.4 0.44... (12 Replies)
Discussion started by: Zooma
12 Replies

10. Shell Programming and Scripting

Conditional Column Value

Hi Folks, I'm trying tog ain further experience with shell programming and have set my a small goal of writing a little filesystem monitoring script. So far my output is as follows: PACMYDB03 Filesystem Size Used Avail Use% Status /usr/local/mysql/data ... (5 Replies)
Discussion started by: Axleuk
5 Replies
Bio::TreeIO::svggraph(3pm)				User Contributed Perl Documentation				Bio::TreeIO::svggraph(3pm)

NAME
Bio::TreeIO::svggraph - A simple output format that converts a Tree object to an SVG output SYNOPSIS
use Bio::TreeIO; my $in = Bio::TreeIO->new(-file => 'input', -format => 'newick'); my $out = Bio::TreeIO->new(-file => '>output', -format => 'svggraph'); while( my $tree = $in->next_tree ) { my $svg_xml = $out->write_tree($tree); } DESCRIPTION
This outputs a tree as an SVG graphic using the SVG::Graph API FEEDBACK
Mailing Lists User feedback is an integral part of the evolution of this and other Bioperl modules. Send your comments and suggestions preferably to the Bioperl mailing list. Your participation is much appreciated. bioperl-l@bioperl.org - General discussion http://bioperl.org/wiki/Mailing_lists - About the mailing lists Support Please direct usage questions or support issues to the mailing list: bioperl-l@bioperl.org rather than to the module maintainer directly. Many experienced and reponsive experts will be able look at the problem and quickly address it. Please include a thorough description of the problem with code and data examples if at all possible. Reporting Bugs Report bugs to the Bioperl bug tracking system to help us keep track of the bugs and their resolution. Bug reports can be submitted via the web: https://redmine.open-bio.org/projects/bioperl/ AUTHOR - Brian OConnor Email brian.oconnor-at-excite.com CONTRIBUTORS
Allen Day Guillaume Rousse, Guillaume-dot-Rousse-at-inria-dot-fr APPENDIX
The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _ new Title : new Usage : my $obj = Bio::TreeIO::svggraph->new(); Function: Builds a new Bio::TreeIO::svggraph object Returns : Bio::TreeIO::svggraph Args :-width => image width (default 1600) -height => image height (default 1000) -margin => margin (default 30) -stroke => stroke color (default 'black') -stroke_width=> stroke width (default 2) -font_size=> font size (default '10px') -nomalize => undef or 'log' (default is undef) write_tree Title : write_tree Usage : $treeio->write_tree($tree); Function: Write a tree out to data stream in newick/phylip format Returns : none Args : Bio::Tree::TreeI object decorateRoot Title : _decorateRoot Usage : internal methods Function: Example : Returns : Args : next_tree Title : next_tree Usage : Function: Sorry not possible with this format Returns : none Args : none perl v5.14.2 2012-03-02 Bio::TreeIO::svggraph(3pm)
All times are GMT -4. The time now is 06:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy