substract column based on some criteria

substract column based on some criteria
# 1
03-18-2010
substract column based on some criteria

Please guide if you know how to solve this.

I have a tab delimited INPUT FILE where each record is separated by -----
The OUTPUT file required is :
Output is based on this criteria:

In a record, If column2(row1) > column2(row2) then subtract row2(column3) from row1(column2) and so on till the rows are found. But if column2(row1) < column2(row2) then subtract row1(column3) from row2(column2) and so on.
If there is only 1 row in a record then print 'Xyz 0 value of Column4'

(4935402-4932368)-1 has been written only for clarity but the value of this expression is required.

Last edited by Franklin52; 03-18-2010 at 06:14 AM.. Reason: Please use code tags!
 sam_2921 View Public Profile for sam_2921 Find all posts by sam_2921
# 2
03-18-2010
Something like this?
 Franklin52 View Public Profile for Franklin52 Find all posts by Franklin52
# 3
03-18-2010
Thanks for your response Franklin. I'll take care of the text formatting. But there is some problem with the output as there are negative values in the output, whereas a smaller number has to be subtracted from a larger number each time.
 sam_2921 View Public Profile for sam_2921 Find all posts by sam_2921
# 4
03-18-2010
Can you post the desired output from the given input file?
 Franklin52 View Public Profile for Franklin52 Find all posts by Franklin52
# 5
03-19-2010
The desired OUTPUT File is :
The difference between records is - numbers in row 2 are either in descending order or ascending order and the subtraction varies accordingly.

Thanks.
 sam_2921 View Public Profile for sam_2921 Find all posts by sam_2921
# 6
03-19-2010
If I understand your question then this should be the criteria:

Quote:
If column2(row1) > column2(row2) then print row1(column2)-row2(column3)-1
If column2(row1) < column2(row2) then print row2(column2)-row1(column3)-1
In that case you can't get the desired output as you posted.

This command uses the criteria above:
and the output is:

Regards
 Franklin52 View Public Profile for Franklin52 Find all posts by Franklin52
# 7
03-19-2010
I have tried to simplify my problem. Please see if you can help.
Now there is only increasing numbers in column.

INPUT FILE
OUTPUT FILE
values written in [ ] are only for explanation purpose.

 sam_2921 View Public Profile for sam_2921 Find all posts by sam_2921

Test Your Knowledge in Computers #402
Difficulty: Medium
The term 3D printing originally referred to a powder bed process employing standard and custom inkjet print heads.
True or False?

Need a Linux command for find/replace column based on specific criteria.

I'm new to shell programming, I have a huge text file in the following format, where columns are separated by single space: ACA MEX 4O_ \$98.00 \$127.40 \$166.60 0:00 0:00 0 ; ACA YUL TS_ \$300.00 \$390.00 \$510.00 0:00 0:00 0 ; ACA YYZ TS_ \$300.00 \$390.00 \$510.00 0:00 0:00 0 ; ADZ YUL TS_ \$300.00...

Delete duplicate row based on criteria

Hi, I have an input file as shown below: 20140102;13:30;FR-AUD-LIBOR-1W;2.495 20140103;13:30;FR-AUD-LIBOR-1W;2.475 20140106;13:30;FR-AUD-LIBOR-1W;2.495 20140107;13:30;FR-AUD-LIBOR-1W;2.475 20140108;13:30;FR-AUD-LIBOR-1W;2.475 20140109;13:30;FR-AUD-LIBOR-1W;2.475...

Match based on criteria to file

Trying to match \$1 of target.txt to \$5 of file.txt. If there is a match then in an output.txt file \$1,\$1 (row underneath),\$6,\$4,\$7 from file.txt are printed on the same line as \$1 of target.txt. The input is from excel and the output should be tab-deliminated. Thank you :). target.txt...

Select lines from a file based on a criteria

Hi I need to select lines from a txt file, I have got a line starting with ZMIO:MSISDN= and after a few line I have another line starting with 'MOBILE STATION ISDN NUMBER' and another one starting with 'VLR-ADDRESS' I need to copy these three lines as three different columns in a separate...

How to substract selective values in multi row, multi column file (using awk or sed?)

Hi, I have a problem where I need to make this input: nameRow1a,text1a,text2a,floatValue1a,FloatValue2a,...,floatValue140a nameRow1b,text1b,text2b,floatValue1b,FloatValue2b,...,floatValue140b look like this output: nameRow1a,text1b,text2a,(floatValue1a - floatValue1b),(floatValue2a -...

How to fetch files right below based on some matching criteria?

I have a requirement where in i need to select records right below the search criteria qwertykeyboard white 10 20 30 30 40 50 60 70 80 qwertykeyboard black 40 50 60 70 90 100 qwertykeyboard and white are headers separated by a tab. when i execute my script..i would be searching...

How to select files based on a criteria?

I have a file..... xxx 2345 455 abc 345 555 cdf 456 777 fff 555 888 Now my requirement is, Say if, i want to select only those records prior to the record fff 555 888... how do i go about doing this in unix.... The fff would be hardcoded as it wud be fixed and everytime when i...

Merging Lines based on criteria

Hello, Need help with following scenario. A file contains following text: {beginning of file} New: This is a new record and it is not on same line. Since I have lost touch with script take this challenge and bring all this in one line. New: Hello losttouch. You seem to be struggling...

need to get a portion of entries in file based on a criteria --- Help please

All, Below is the file, what i need to do is take the text in between the /*-- and --*/ , i mean the jobs. Then i have grep for system name . If the job is there in system 1 i have to print to a file. Basically i want to take all the jobs that are in system1 to another file . because...

Select records based on search criteria on first column

Hi All, I need to select only those records having a non zero record in the first column of a comma delimited file. Suppose my input file is having data like: "0","01/08/2005 07:11:15",1,1,"Created",,"01/08/2005" "0","01/08/2005 07:12:40",1,1,"Created",,"01/08/2005"...