Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Add values to file in 2 new columns Post 303044019 by rdrtx1 on Wednesday 12th of February 2020 02:43:46 PM
Old 02-12-2020
Code:
awk '{
line[NR]=$0;
pp[NR] = $2
ll[NR] = $1
x[NR] = $4
y[NR] = $5
z[NR] = $6
rc[$1,$2]++
} END {
first = 1
count = 0
for ( i=1 ; i <= NR ; i++ ) {
if (pp[i] == pp[i+1] && ll[i] == ll[i+1]) {
printf line[i];
} else {
printf line[i]
last = i
count++
dx = x[first]-x[last]
dy = y[first]-y[last]
el = z[first]-z[last]
ele = sqrt(el^2)
len[count] = sqrt(dx^2+dy^2)
if (rc[ll[i], pp[i]]==1) {
len[count]=0
ele=0;
}
printf ("%8.2f %8.2f", len[count],ele)
first = i+1
}
print "";
}
}' file


Last edited by rdrtx1; 02-18-2020 at 07:22 PM..
This User Gave Thanks to rdrtx1 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to flip values of two columns and add an extra column

Hi guys, Couldn't find the solution of this problem. Please Help! I have a file- Input_File TC200232 92 30 TC215306 2 74 TC210135 42 14 I want an output file in which if column2>column3, the values are swapped and an additional column with value Rev_Com is... (4 Replies)
Discussion started by: smriti_shridhar
4 Replies

2. UNIX for Dummies Questions & Answers

combine the values from the first two columns within a file

Hello everybody, I have a text file containing 10,000 rows and 5000 columns. The values are separated by a tab. Ex. file_ex.ped 1 mike 0 0 2 1 A A G G C T A G 1 jack 0 0 2 2 T A G T C A A C 1 Mary 0 0 1 2 A T G C A T G C ... I would like a out put file 1 mike 0 0 2 1 AA GG CT AG 1... (7 Replies)
Discussion started by: Unilearn
7 Replies

3. Shell Programming and Scripting

Math operations with file columns values.

Hello everybody, I have some large files containing statistical data. The data is stored in the following generic format: >cat my_file 1, 2, 3 1, 2, 3 1, 2, 3 > The values of columns no.2 and 3 are expressed in bytes. I would like to transform them in Megabytes, by dividing them with... (3 Replies)
Discussion started by: fabian23
3 Replies

4. Shell Programming and Scripting

Copy values from columns matching in those in second file.

Hi All, I have two sets of files. Set 1: 100 text files with extension .txt with names like 1.txt, 2.txt, 3.txt until 100.txt Set 2: One big file with extension .dat The text files have some records in columns like this: 0.7316431 82628 0.7248189 82577 0.7248182 81369 0.7222999... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

5. UNIX for Dummies Questions & Answers

Subtracting values from 2 columns in a file

Hello, I have a file with 5 columns that looks like this: A1BG chr19 + 58863335 58866549 A1BG chr19 - 58858171 58864865 A2LD1 chr13 - 101182417 101186056 A2LD1 chr13 - 101182417 101241046 A2M chr12 - 9220303 9268558 A2ML1 ... (5 Replies)
Discussion started by: wolf_blue
5 Replies

6. UNIX for Dummies Questions & Answers

Removing columns from a text file that do not have any values in second and third columns

I have a text file that has three columns. But at the end of the text file, there are trailing lines that have missing second and third columns: 4 0.04972604 KLHL28 4 0.0497332 CSTB 4 0.04979822 AIF1 4 0.04983331 DECR2 4 0.04990344 KATNB1 4 4 4 4 How can I remove the trailing... (3 Replies)
Discussion started by: evelibertine
3 Replies

7. Shell Programming and Scripting

for uniq entries add values in corresponding columns

Hi, I have a file as listed below.. What I want to get is for each unique value in column 1 the corresponding values in the rest of the columns should be summed up.. AAK1 0 1 0 11 AAK1 0 0 1 1 AAK1 0 0 1 2... (2 Replies)
Discussion started by: Diya123
2 Replies

8. Shell Programming and Scripting

Add the values in second and third columns with group by on first column.

Hi All, I have a pipe seperated file. I need to add the values in second and third columns with group by on first column. MYFILE_28012012_1115|47|173.90 MYFILE_28012012_1115|4|0.00 MYFILE_28012012_1115|6|22.20 MYFILE_28012012_1116|47|173.90 MYFILE_28012012_1116|4|0.00... (3 Replies)
Discussion started by: angshuman
3 Replies

9. Shell Programming and Scripting

Add values in 2 columns and subtract from third

Hi All, I have a file with thousands of lines in the following format, where Field1=First 8 characters Field2-9-16 characters Field3=17-26 characters I need to add Field 1 and Field2 and subtract the result from Field 3. Field3=Field3 - (Field1 + Field2) 0012.00 0010.00 0001576.53... (4 Replies)
Discussion started by: nua7
4 Replies

10. UNIX for Beginners Questions & Answers

Awk: compare values in two columns of the same file

I'm trying to learn awk, but I've hit a roadblock with this problem. I have a hierarchy stored in a file with 3 columns: id name parentID 4 D 2 2 B 1 3 C 1 1 A 5 I need to check if there are any values in column 3 that are not represented anywhere in column 1. I've tried this: awk '{arr;}... (7 Replies)
Discussion started by: kaktus
7 Replies
PVS(8)							      System Manager's Manual							    PVS(8)

NAME
pvs - report information about physical volumes SYNOPSIS
pvs [-a|--all] [--aligned] [-d|--debug] [-h|-?|--help] [--ignorelockingfailure] [--nameprefixes] [--noheadings] [--nosuffix] [-o|--options [+]Field[,Field]] [-O|--sort [+|-]Key1[,[+|-]Key2[,...]]] [-P|--partial] [--rows] [--segments] [--separator Separator] [--unbuffered] [--units hHbBsSkKmMgGtTpPeE] [--unquoted] [-v|--verbose] [--version] [PhysicalVolume [PhysicalVolume...]] DESCRIPTION
pvs produces formatted output about physical volumes. OPTIONS
See lvm for common options. --columns. --all Include information in the output about devices that have not been initialized with pvcreate. --aligned Use with --separator to align the output columns. --nameprefixes Add an "LVM2_" prefix plus the field name to the output. Useful with --noheadings to produce a list of field=value pairs that can be used to set environment variables (for example, in udev (7) rules). --noheadings Suppress the headings line that is normally the first line of output. Useful if grepping the output. --nosuffix Suppress the suffix on output sizes. Use with --units (except h and H) if processing the output. -o, --options Comma-separated ordered list of columns. Precede the list with '+' to append to the default selection of columns. Use -o pv_all to select all physical volume columns, and -o pvseg_all to select all Physical Volume segment columns. Use -o help to view the full list of columns available. Column names include: pv_fmt, pv_uuid, dev_size, pv_name, pv_mda_free, pv_mda_size, pe_start, pv_size, pv_free, pv_used, pv_attr, pv_pe_count, pv_pe_alloc_count, pv_tags, pv_mda_count, pvseg_start, and pvseg_size. With --segments, any "pvseg_" prefixes are optional; otherwise any "pv_" prefixes are optional. Columns mentioned in vgs (8) can also be chosen. The pv_attr bits are: (a)llocatable and e(x)ported. --segments Produces one line of output for each contiguous allocation of space on each Physical Volume, showing the start (pvseg_start) and length (pvseg_size) in units of physical extents. -O, --sort Comma-separated ordered list of columns to sort by. Replaces the default selection. Precede any column with - for a reverse sort on that column. --rows Output columns as rows. --separator Separator String to use to separate each column. Useful if grepping the output. --unbuffered Produce output immediately without sorting or aligning the columns properly. --units hHbBsSkKmMgGtTpPeE All sizes are output in these units: (h)uman-readable, (b)ytes, (s)ectors, (k)ilobytes, (m)egabytes, (g)igabytes, (t)erabytes, (p)etabytes, (e)xabytes. Capitalise to use multiples of 1000 (S.I.) instead of 1024. Can also specify custom units e.g. --units 3M --unquoted When used with --nameprefixes, output values in the field=value pairs are not quoted. SEE ALSO
lvm(8), pvdisplay(8), lvs(8), vgs(8) Sistina Software UK LVM TOOLS 2.02.67(2) (2010-06-04) PVS(8)
All times are GMT -4. The time now is 08:34 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy