Sponsored Content
Top Forums Shell Programming and Scripting awk to adjust coordinates in field based on sequential numbers in another field Post 302990535 by MadeInGermany on Friday 27th of January 2017 04:59:03 PM
Old 01-27-2017
If I run your awk on your input then I do not get your output.
But maybe I have understood your description.
If your file is sorted by $4 and $6 (so $6 sequences are in adjacent lines),
then the following can do it:
Code:
awk '
# print from stored values
function prt(){
  print p1 ":" (p6start==1 ? p2 : p2+p6start) "-" p2+p6, p5
}
($4!=p4 || $6!=p6+1) {
# new sequence, print the previous sequence
  if (NR>1) prt()
  p6start=$6  
}
{
# store the values that we need later
  p1=$1
  p2=$2
  p4=$4
  p5=$5
  p6=$6
}
END { prt() }
' file

A problem is the "late" end-of-sequence detection. This is solved with storing the previous values, and an END section, and a print function.
This User Gave Thanks to MadeInGermany For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find top N values for field X based on field Y's value

I want to find the top N entries for a certain field based on the values of another field. For example if N=3, we want the 3 best values for each entry: Entry1 ||| 100 Entry1 ||| 95 Entry1 ||| 30 Entry1 ||| 80 Entry1 ||| 50 Entry2 ||| 40 Entry2 ||| 20 Entry2 ||| 10 Entry2 ||| 50... (1 Reply)
Discussion started by: FrancoisCN
1 Replies

2. UNIX for Dummies Questions & Answers

awk - Summing a field based on another field

So, I need to do some summing. I have an Apache log file with the following as a typical line: 127.0.0.1 - frank "GET /apache_pb.gif HTTP/1.0" 200 2326 Now, what I'd like to do is a per-minute sum. So, I can have awk tell me the individual minutes, preserving the dates(since this is a... (7 Replies)
Discussion started by: treesloth
7 Replies

3. Shell Programming and Scripting

awk, comma as field separator and text inside double quotes as a field.

Hi, all I need to get fields in a line that are separated by commas, some of the fields are enclosed with double quotes, and they are supposed to be treated as a single field even if there are commas inside the quotes. sample input: for this line, 5 fields are supposed to be extracted, they... (8 Replies)
Discussion started by: kevintse
8 Replies

4. Shell Programming and Scripting

AWK: Pattern match between 2 files, then compare a field in file1 as > or < field in file2

First, thanks for the help in previous posts... couldn't have gotten where I am now without it! So here is what I have, I use AWK to match $1 and $2 as 1 string in file1 to $1 and $2 as 1 string in file2. Now I'm wondering if I can extend this AWK command to incorporate the following: If $1... (4 Replies)
Discussion started by: right_coaster
4 Replies

5. UNIX for Dummies Questions & Answers

[Solved] awk solution to add sequential numbers based on a word

Hi experts, I've been struggling to format a large genetic dataset. It's complicated to explain so I'll simply post example input/output $cat input.txt ID GENE pos start end blah1 coolgene 1 3 5 blah2 coolgene 1 4 6 blah3 coolgene 1 4 ... (4 Replies)
Discussion started by: torchij
4 Replies

6. Shell Programming and Scripting

awk to combine matches and use a field to adjust coordinates in other fields

Trying to output a result that uses the data from file to combine and subtract specific lines. If $4 matches in each line then the last $6 value is added to $2 and that becomes the new$3. Each matching line in combined into one with $1 then the original $2 then the new$3 then $5. For the cases... (4 Replies)
Discussion started by: cmccabe
4 Replies

7. Shell Programming and Scripting

awk to update value in field based on another field

In the tab-delimeted input file below I am trying to use awk to update the value in $2 if TYPE=ins in bold, by adding the value of HRUN= in italics. In the below since in line 1 TYPE=ins the 117282541 value in $2 has 6 added because that is the value of HRUN=. Hopefully the awk is a start but I... (2 Replies)
Discussion started by: cmccabe
2 Replies

8. Shell Programming and Scripting

awk to adjust text and count based on value in field

The below awk executes as is and produces the current output. It isvery close but what Ican not seem to do is add the -exon..., the ... portion comes from $1 and the _exon is static and will never change. If there is + sign in $4 then the ... is in acending order or sequential. If there is a - in... (2 Replies)
Discussion started by: cmccabe
2 Replies

9. Shell Programming and Scripting

Perl to adjust coordinates based on repeat string

In the file below I am trying to count the given repeats of A,T,C,G in each string of letters. Each sequence is below the > and it is possible for a string of repeats to wrap from the line above. For example, in the first line the last letter is a T and the next lines has 3 more. I think the below... (10 Replies)
Discussion started by: cmccabe
10 Replies

10. UNIX for Beginners Questions & Answers

Problem with getting awk to multiply a field by a value set based on condition of another field

Hi, So awk is driving me crazy on this one. I have searched everywhere and read man, docs and every related post Google can find and still no luck. The actual files I need to run this on are sensitive in nature, but it is the same thing as if I needed to calculate weighted grades for multiple... (15 Replies)
Discussion started by: cotilloe
15 Replies
sccs-prt(1)							   User Commands						       sccs-prt(1)

NAME
sccs-prt, prt - display delta table information from an SCCS file SYNOPSIS
/usr/ccs/bin/prt [-abdefistu] [-cdate-time] [-rdate-time] [-ysid] s.filename... DESCRIPTION
prt prints selected portions of an SCCS file. By default, it prints the delta table (version log). If a directory name is used in place of the s.filename argument, the prt command applies to all s.files in that directory. Unreadable s.files produce an error; processing continues with the next file (if any). The use of `-' as the s.filename argument indicates that the names of files are to be read from the standard input, one s.file per line. OPTIONS
If any option other than -y, -c, or -r is supplied, the name of each file being processed (preceded by one NEWLINE and followed by two NEW- LINE characters) appears above its contents. If none of the -u, -f, -t, or -b options are used, -d is assumed. -s, -i are mutually exclusive, as are -c and -r. -a Display log entries for all deltas, including those marked as removed. -b Print the body of the s.file. -d Print delta table entries. This is the default. -e Everything. This option implies -d, -i, -u, -f, and -t. -f Print the flags of each named s.file. -i Print the serial numbers of included, excluded, and ignored deltas. -s Print only the first line of the delta table entries; that is, only up to the statistics. -t Print the descriptive text contained in the s.file. -u Print the user-names and/or numerical group IDs of users allowed to make deltas. -cdate-time Exclude delta table entries that are specified cutoff date and time. Each entry is printed as a single line, preceded by the name of the SCCS file. This format (also produced by -r , and -y) makes it easy to sort multiple delta tables in chronological order. When both -y and -c, or -y and -r are supplied, prt stops printing when the first of the two condi- tions is met. -rdate-time Exclude delta table entries that are newer than the specified cutoff date and time. -ysid Exclude delta table entries made prior to the SID specified. If no delta in the table has the specified SID, the entire table is printed. If no SID is specified, the most recent delta is printed. USAGE
Output Format The following format is used to print those portions of the s.file that are specified by the various options. o NEWLINE o Type of delta (D or R) o SPACE o SCCS delta ID (SID) o TAB o Date and time of creation in the form: yy/mm/dd hh/mm/ss o SPACE o Username the delta's creator o TAB o Serial number of the delta o SPACE o Predecessor delta's serial number o TAB o Line-by-line change statistics in the form: inserted/deleted/unchanged o NEWLINE o List of included deltas, followed by a NEWLINE (only if there were any such deltas and the -i options was used) o List of excluded deltas, followed by a NEWLINE (only if there were any such deltas and the -i options was used) o List of ignored deltas, followed by a NEWLINE (only if there were any such deltas and the -i options was used) o List of modification requests (MRs), followed by a NEWLINE (only if any MR numbers were supplied). o Lines of the delta commentary (if any), followed by a NEWLINE. EXAMPLES
Example 1: Examples of prt. The following command: example% /usr/ccs/bin/prt -y program.c produces a one-line display of the delta table entry for the most recent version: s.program.c: D 1.6 88/07/06 21:39:39 username 5 4 00159/00080/00636... ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWsprot | +-----------------------------+-----------------------------+ SEE ALSO
sccs(1), sccs-cdc(1), sccs-delta(1), sccs-get(1), sccs-help(1), sccs-prs(1), sccs-sact(1), sccs-sccsdiff(1), what(1), sccsfile(4), attributes(5) DIAGNOSTICS
Use the SCCS help command for explanations (see sccs-help(1)). SunOS 5.10 5 Oct 1990 sccs-prt(1)
All times are GMT -4. The time now is 10:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy