Sponsored Content
Full Discussion: Subtract field values
Top Forums Shell Programming and Scripting Subtract field values Post 302372997 by Franklin52 on Thursday 19th of November 2009 07:48:03 AM
Old 11-19-2009
Try this:

Code:
awk '{
  getline s < "file1"; split(s,a,":")
  n=split($0,b,":")
  out=b[1]
  for(i=2;i<=n;i++) {
    out=out ":" b[i] - a[i]
  }
  print out
}' file2

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Subtract 100 from first field in long list? Simple manipulation?

It sounds so easy to do. I have a file thats laid out like this.. number text text text text (etc about 15 times with various text fields) I want to take the first field, "number", subtract 100 from it, and then put it back in the file. a simple little manipulation of the first field in... (4 Replies)
Discussion started by: LordJezo
4 Replies

2. Shell Programming and Scripting

Need help with switching field/column values

Hi all, I need some help on switching field/column values. For example I have a file name data.txt which contains: a b a b a b and I want to switch a and b and save it to the same file. the file data.txt then will have: b a b a b a The problem is, well, I know how to... (7 Replies)
Discussion started by: sonyd8
7 Replies

3. 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

4. Shell Programming and Scripting

adding field values if field matches

hi i have file as below , i want to add duplicate records like bell_bb to one record with valuve as 15 ( addition of both ) any oneline awk script to achive this ? header 0 CAMPAIGN_NAME 1 Bell_BB 14 Bell_MONTHLY 803 SOLO_UNBEATABLE 644 Bell_BB 1 Bell_MONTHLY 25 SOLO_UNBEATABLE... (4 Replies)
Discussion started by: raghavendra.cse
4 Replies

5. Shell Programming and Scripting

Quoting the values in second field

Hi, I have got a file comp_data containing the below data : 38232836|9302392|49 39203827|8203203,3933203|52 72832788|567,3245,2434324|100 This file can have many rows like shown above. I want the values separated by "," in second column(taking "|" as delimiter) to be in quotes. These... (2 Replies)
Discussion started by: msabhi
2 Replies

6. Shell Programming and Scripting

Concatenate last field values for all occurences

Hello all, Maybe you can help me with an awk script to get what I need. I have the input file with format below: REQUEST|79023787741690|738227864597|985 REQUEST|79024002151717|738229423534|985 REQUEST|79024002151717|738229423534|*985 NDS-REQUEST|79024002151717|738229423534 ... (4 Replies)
Discussion started by: Ophiuchus
4 Replies

7. 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

8. Shell Programming and Scripting

Count the field values in a file

Hi I have a file with contents like : 101,6789556897,0000795369 - seq - fmt_recs187] - avg_recs 101,4678354769,0000835783 - seq - fmt_recs98] - avg_recs 221,5679787008,0001344589 - seq - fmt_recs1283] - avg_recs I need to find the sum of the all the values (which are in bold). here... (6 Replies)
Discussion started by: rkrish
6 Replies

9. Shell Programming and Scripting

awk to subtract from values in file

data.txt: 0,mq_conn_open_error,1444665949,734,/PROD/G/cicsitlp/sys/unikixmain.log,64K,mq_conn_open_error,62022,0,733--734 0,mq_conn_open_error,1444666249,734,/PROD/G/cicsitlp/sys/unikixmain.log,64K,mq_conn_open_error,62022,0,734--734... (7 Replies)
Discussion started by: SkySmart
7 Replies

10. Programming

Subtract values based on records

Hi Guys, I am having below tables in oracle T1 ID F_TYPE F_AMT DATE_COL 1 F 6 11-Feb-16 1 D 2 11-Feb-16 1 D 2 11-Feb-16 1 F 6 11-Feb-16 1 F 2 12-Mar-16 1 D 3 12-Mar-16 1 F 4 10-Apr-16 1 F 4 11-Apr-16 1 D 1 11-Apr-16 T2 ID START_DATE END_DATE F_ID FLAG... (0 Replies)
Discussion started by: rohit_shinez
0 Replies
SPLIT(1)						      General Commands Manual							  SPLIT(1)

NAME
split - split a file into pieces SYNOPSIS
split [ option ... ] [ file ] DESCRIPTION
Split reads file (standard input by default) and writes it in pieces of 1000 lines per output file. The names of the output files are xaa, xab, and so on to xzz. The options are -n Split into n-line pieces. -e expression File divisions occur at each line that matches a regular expression; see regexp(6). Multiple -e options may appear. If a subex- pression of expression is contained in parentheses (...), the output file name is the portion of the line which matches the subex- pression. -f stem Use stem instead of x in output file names. -s suffix Append suffix to names identified under -e. -x Exclude the matched input line from the output file. -i Ignore case in option -e; force output file names (excluding the suffix) to lower case. SOURCE
/sys/src/cmd/split.c SEE ALSO
sed(1), awk(1) grep(1), regexp(6) SPLIT(1)
All times are GMT -4. The time now is 07:45 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy