Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Split a file based on number sum at the second column and the third column. Post 303044707 by demo10 on Monday 2nd of March 2020 05:06:12 AM
Old 03-02-2020
Quote:
Originally Posted by nezabudka
Hi
Maybe just like that?
Code:
awk '
/^\S+\s+12109/,/^(\S+\s+){2}14678\s/ {print > "file1"}
/^\S+\s+15573/,/^(\S+\s+){2}15612\s/ {print > "file2"}
/^\S+\s+20498/,/^(\S+\s+){2}21668\s/ {print > "file3"}
' file


Thank you so much. This is what I need.


Quote:
Originally Posted by nezabudka
maybe so?
Code:
#!/bin/bash

step=2999
declare -i start=12109 end=start+step count=1
stop=$(awk '{if($3>max) max=$3} END {print max}' file)

while [ $end -le $stop ]; do
        awk -vA=$start -vZ=$end -vf="file$count" '
                $2>=A && $3<=Z {print > f}
        ' file
        start+=step
        end+=step
        count+=1
done

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How do I sum one column based on another column?

Hi, I am new to this forum and new to awk. I have a file that contains 2 columns. Heres an example of what it looks like: 10 + 20 + 40 + 50 - 70 - So the file is tab-delimited. What I want to do is add 10 to column 1 whenever column 2 is + and substract 10 from column 1... (1 Reply)
Discussion started by: phil_heath
1 Replies

2. Shell Programming and Scripting

Split single file into multiple files based on the number in the column

Dear All, I would like to split a file of the following format into multiple files based on the number in the 6th column (numbers 1, 2, 3...): ATOM 1 N GLY A 1 -3.198 27.537 -5.958 1.00 0.00 N ATOM 2 CA GLY A 1 -2.199 28.399 -6.617 1.00 0.00 ... (3 Replies)
Discussion started by: tomasl
3 Replies

3. Shell Programming and Scripting

Split the file based on column

Hi, I have a file sample_1.txt (300k rows) which has data like below: * Also each record is around 64k bytes 11|1|abc|102553|125589|64k bytes of data 10|2|def|123452|123356|...... 13|2|geh|144351|121123|... 25|4|fgh|165250|118890|.. 14|1|abc|186149|116657|......... (6 Replies)
Discussion started by: sol_nov
6 Replies

4. Shell Programming and Scripting

Sum Of Column Based On Column Condition

I have a following inputfile MT,AP,CDM,TTML,MUM,GS,SUCC,3 MT,AP,CDM,TTSL,AP,GS,FAIL,9 MT,AP,CDM,RCom,MAH,GS,SUCC,3 MT,AP,CDM,RTL,HP,GS,SUCC,1 MT,AP,CDM,Uni,UPE,GS,SUCC,2 MT,AP,CDM,Uni,MUM,GS,SUCC,2 TTSL,AP,GS,MT,MAH,CDM,SUCC,20 TTML,AP,GS,MT,MAH,CDM,FAIL,10... (2 Replies)
Discussion started by: siramitsharma
2 Replies

5. Shell Programming and Scripting

awk to sum a column based on duplicate strings in another column and show split totals

Hi, I have a similar input format- A_1 2 B_0 4 A_1 1 B_2 5 A_4 1 and looking to print in this output format with headers. can you suggest in awk?awk because i am doing some pattern matching from parent file to print column 1 of my input using awk already.Thanks! letter number_of_letters... (5 Replies)
Discussion started by: prashob123
5 Replies

6. Shell Programming and Scripting

Sum column values based in common identifier in 1st column.

Hi, I have a table to be imported for R as matrix or data.frame but I first need to edit it because I've got several lines with the same identifier (1st column), so I want to sum the each column (2nd -nth) of each identifier (1st column) The input is for example, after sorted: K00001 1 1 4 3... (8 Replies)
Discussion started by: sargotrons
8 Replies

7. Shell Programming and Scripting

Split column data if the table has n number of column's

please write a shell script Table -------------------------- 1 2 3 a b c 3 4 5 c d e 7 8 9 f g h Output should be like this --------------- 1 2 3 3 4 5 7 8 9 a b c c d e f g h (1 Reply)
Discussion started by: Priti2277
1 Replies

8. Shell Programming and Scripting

Split column data if the table has n number of column's with some record

Split column data if the table has n number of column's with some record then how to split n number of colmn's line by line with records Table --------- Col1 col2 col3 col4 ....................col20 1 2 3 4 .................... 20 a b c d .................... v ... (11 Replies)
Discussion started by: Priti2277
11 Replies

9. Shell Programming and Scripting

Sum of a column as new column based on header in a script

Hello, I am trying to store sum of a column as a new column inside a file but have to find the column names dynamically I/p c1,c2,c3,c4,c5 10,20,30,40,50 20,30,40,50,60 If i want to find sum only column c1, c3 and output it as c6,c7 O/p c1,c2,c3,c4,c5,c6,c7 10,20,30,40,50,30,70... (6 Replies)
Discussion started by: mkathi
6 Replies

10. UNIX for Beginners Questions & Answers

Sum in file based column

Hi All, I have a file as below and want to sum based on the id in the first column Input 10264;ATE; 12 10265;SES;11 10266AUT;50 10264;ATE;10 10265;SES;13 10266AUT;89 10264;ATE;1 10265;SES;15 10266AUT;78 Output 10264;ATE; 23 10265;SES;39 10266AUT;139 (6 Replies)
Discussion started by: arunkumar_mca
6 Replies
Bio::Graphics::Wiggle(3pm)				User Contributed Perl Documentation				Bio::Graphics::Wiggle(3pm)

NAME
Bio::Graphics::Wiggle -- Binary storage for dense genomic features SYNOPSIS
# all positions are 1-based my $wig = Bio::Graphics::Wiggle->new('./test.wig', $writeable, { seqid => $seqid, start => $start, step => $step, min => $min, max => $max }); $wig->erase; my $seqid = $wig->seqid('new_id'); my $max = $wig->max($new_max); my $min = $wig->min($new_min); my $step = $wig->step($new_step); # data stored at modulus step == 0; all else is blank $wig->set_value($position => $value); # store $value at position $wig->set_values($position => @values); # store array of values at position $wig->set_range($start=>$end,$value); # store the same $value from $start to $end my $value = $wig->value($position); # fetch value from position my $values = $wig->values($start,$end); # fetch range of data from $start to $end $wig->window(100); # sample window size $wig->smoothing('mean'); # when sampling, compute the mean value across sample window my $values = $wig->values($start,$end,$samples); # fetch $samples data points from $start to $end DESCRIPTION
IMPORTANT NOTE: This implementation is still not right. See http://genomewiki.ucsc.edu/index.php/Wiggle for a more space-efficient implementation. This module stores "wiggle" style quantitative genome data for display in a genome browser application. The data for each chromosome (or contig, or other reference sequence) is stored in a single file in the following format: 256 byte header 50 bytes seqid, zero-terminated C string 4 byte long integer, value of "step" (explained later) 4 byte perl native float, the "min" value 4 byte perl native float, the "max" value 4 byte long integer, value of "span" 4 byte perl native float, the mean 4 byte perl native float, the standard deviation 2 byte unsigned short, the version number (currently version 0) 4 byte long integer, sequence start position (in 0-based coordinates) null padding to 256 bytes for future use The remainder of the file consists of 8-bit unsigned scaled integer values. This means that all quantitative data will be scaled to 8-bit precision! For a convenient method of creating Wiggle files from UCSC-type WIG input and creating GFF3 output, please see Bio::Graphics::Wiggle::Loader. METHODS
Constructor and Accessors $wig = Bio::Graphics::Wiggle->new($filename,$writeable,{options}) Open/create a wiggle-format data file: $filename -- path to the file to open/create $writeable -- boolean value indicating whether file is writeable. Missing files will only be created if $writeable set to a true value. If path is empty (undef or empty string) and writeable is true, new() will create a temporary file that will be deleted when the object goes out of scope. {options} -- hash ref of the following named options, only valid when creating a new wig file with $writeable true. option name description default ----------- ----- ------- seqid name/id of sequence empty name min minimum value of data points 0 max maximum value of data points 255 step interval between data points 1 span width of data points value of "step" The "step" can be used to create sparse files to save space. By default, step is set to 1, in which case a data value will be stored at each base of the sequence. By setting step to 10, then each value is taken to correspond to 10 bp, and the file will be 10x smaller. For example, consider this step 5 data set: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 20 . . . . 60 . . . . 80 . . . We have stored the values "20" "60" and "80" at positions 1, 6 and 11, respectively. When retrieving this data, it will appear as if positions 1 through 5 have a value of 20, positions 6-10 have a value of 60, and positions 11-14 have a value of 80. In the data file, we store, positions 1,6,and 11 in adjacent bytes. Note that no locking is performed by this module. If you wish to allow multi-user write access to the databases files, you will need to flock() the files yourself. $seqid = $wig->seqid(['new_id']) $max = $wig->max([$new_max]) $min = $wig->min([$new_min]) $step = $wig->step([$new_step]) $span = $wig->span([$new_span]) $mean = $wig->mean([$new_mean]); $stdev = $wig->stdev([$new_stdev]); These accessors get or set the corresponding values. Setting is only allowed if the file was opened for writing. Note that changing the min, max and step after writing data to the file under another parameter set will produce unexpected (and invalid) results, as the existing data is not automatically updated to be consistent. $trim = $wig->trim([$new_trim]); The trim method sets the trimming method, which can be used to trim out extreme values. Three methods are currently supported: none No trimming stdev Trim 1 standard deviation above and below mean stdevN Trim N standard deviations above and below the mean In "stdevN", any can be any positive integer. Setting Data $wig->set_value($position => $value) This method sets the value at $position to $value. If a step>1 is in force, then $position will be rounded down to the nearest multiple of step. $wig->set_range($start=>$end, $value) This method sets the value of all bases between $start and $end to $value, honoring step. $sig->set_values($position => @values) This method writes an array of values into the datababase beginning at $position (or the nearest lower multiple of step). If step>1, then values will be written at step intervals. Retrieving Data $value = $wig->value($position) Retrieve the single data item at position $position, or the nearest lower multiple of $step if step>1. $values = $wig->values($start=>$end) Retrieve the values in the range $start to $end and return them as an array ref. Note that you will always get an array of size ($end-$start+1) even if step>1; the data in between the step intervals will be filled in. $values = $wig->values($start=>$end,$samples) Retrieve a sampling of the values between $start and $end. Nothing very sophisticated is done here; the code simply returns the number of values indicated in $samples, smoothed according to the smoothing method selected (default to "mean"), then selected at even intervals from the range $start to $end. The return value is an arrayref of exactly $samples values. $string = $wig->export_to_wif($start,$end) $string = $wig->export_to_wif64($start,$end) Export the region from start to end in the "wif" format. This data can later be imported into another Bio::Graphics::Wiggle object. The first version returns a binary string. The second version returns a base64 encoded version that is safe for ascii-oriented formata such as GFF3 and XML. $wig->import_from_wif($string) $wig->import_from_wif64($string) Import a wif format data string into the Bio::Graphics::Wiggle object. The first version expects a binary string. The second version expects a base64 encoded version that is safe for ascii-oriented formata such as GFF3 and XML. SEE ALSO
Bio::Graphics::Wiggle::Loader, Bio::Graphics::Panel, Bio::Graphics::Glyph, Bio::Graphics::Feature, Bio::Graphics::FeatureFile AUTHOR
Lincoln Stein <lstein@cshl.org>. Copyright (c) 2007 Cold Spring Harbor Laboratory This package and its accompanying libraries is free software; you can redistribute it and/or modify it under the terms of the GPL (either version 1, or at your option, any later version) or the Artistic License 2.0. Refer to LICENSE for the full license text. In addition, please see DISCLAIMER.txt for disclaimers of warranty. perl v5.14.2 2012-02-20 Bio::Graphics::Wiggle(3pm)
All times are GMT -4. The time now is 11:00 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy