Sponsored Content
Top Forums Shell Programming and Scripting Trying to get an awk script to replace values in column Post 302995523 by Eric1 on Thursday 6th of April 2017 11:46:55 PM
Old 04-07-2017
Okay, so for example, here is what is inside one of the Node text files-

Code:
-80.0222 -81.3604 -83.2733 -87.9688 -86.7132 -82.938 -81.6501 -76.9167 -78.9644 -80.2246 
-79.0461 -80.5249 -82.2464 -86.497 -85.8544 -82.4721 -81.4323 -77.8798 -80.7688 -80.987 
-77.9511 -79.6907 -82.1187 -85.737 -84.9415 -81.189 -80.1036 -77.4193 -80.762 -81.287 
-77.4729 -78.9058 -81.1581 -84.3832 -85.2848 -81.6571 -79.811 -77.7476 -81.1131 -81.4729 
-77.2045 -78.5694 -80.4245 -84.6326 -85.4181 -81.7013 -79.8357 -78.016 -81.6587 -81.8589

The input would simply be the user inputting an integer from 1 to 10, which is stored as "userinput" and for now we'll say they input 3, for column 3.
I have a number attached to var1-3, var1 in this case being -86.4149, var2 being -79.6892, and var3 being 3.

I want to replace the values in column 3 in this file along with the other three node files by comparing the values in the column with the numbers attached to var1, var2, and var3. If the values in the column are less than var3 and greater than var1, replace the values in the column with "ttt"

If the values in the column are greater than or equal to var 3 and less than var2, replace the values in the column with "gcc"

So basically a desired result would be this in the case of this example-

Code:
-80.0222 -81.3604 ttt -87.9688 -86.7132 -82.938 -81.6501 -76.9167 -78.9644 -80.2246 
-79.0461 -80.5249 ttt -86.497 -85.8544 -82.4721 -81.4323 -77.8798 -80.7688 -80.987 
-77.9511 -79.6907 ttt -85.737 -84.9415 -81.189 -80.1036 -77.4193 -80.762 -81.287 
-77.4729 -78.9058 ttt -84.3832 -85.2848 -81.6571 -79.811 -77.7476 -81.1131 -81.4729 
-77.2045 -78.5694 ttt -84.6326 -85.4181 -81.7013 -79.8357 -78.016 -81.6587 -81.8589

Also I should note I made an error when referring to the Node files in that code. It should be Node{1..4}.txt not Node {1..4}.txt, the space there was an error on my part, my apologies.

Is this sufficient enough to get my idea across? If any more clarification is needed let me know. I apologize for my stupidity, I'm very new to bash scripting and this forum as well.

Last edited by Scrutinizer; 04-07-2017 at 01:27 AM.. Reason: code tags
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

replace a column values with the first value in column

Hi All, I have a file which has data in following format: "Body_Model","2/1/2007","2/1/2007" "CSCH74","0","61" "CSCS74","0","647" "CSCX74","0","3" "CSYH74","0","299" "CSYS74","0","2514" "CSYX74","0","3" "Body_Model","3/1/2007","3/1/2007" "CSCH74","0","88" "CSCS74","0","489"... (3 Replies)
Discussion started by: sumeet
3 Replies

2. Shell Programming and Scripting

replace the column values.

I have the below file ...where some of the column values should replaced with desired values ....below file u can find that 3 column where ever 'AAA' comes should replaced with ' CC ' NOTE : we have to pass the column number ,AAA,CC (modified value) as the parameters to the code. ... (6 Replies)
Discussion started by: charandevu
6 Replies

3. Shell Programming and Scripting

How to pick values from column based on key values by usin AWK

Dear Guyz:) I have 2 different input files like this. I would like to pick the values or letters from the inputfile2 based on inputfile1 keys (A,F,N,X,Z). I have done similar task by using awk but in that case the inputfiles are similar like in inputfile2 (all keys in 1st column and values in... (16 Replies)
Discussion started by: repinementer
16 Replies

4. UNIX for Dummies Questions & Answers

Replace values in a specified column of a file

Hello, I have a file with four columns and I would like to replace values in the second column only. An arbitrary example is: 100 A 105 B 200 B 205 C 300 C 305 D 400 D 405 E 500 E 505 F I need to replace the second column as shown below: ... (4 Replies)
Discussion started by: Gussifinknottle
4 Replies

5. Shell Programming and Scripting

for each different entry in column 1 extract maximum values from column 2 in unix/awk

Hello, I have 2 columns (1st column has multiple entries but the corresponding values in the column 2 may be the same or different.) however I want to extract unique values for each entry in column 1 by assigning the max value from column 2 SDF4 -0.211654 SDF4 0.978068 ... (1 Reply)
Discussion started by: Diya123
1 Replies

6. Shell Programming and Scripting

Selective Replace awk column values

Hi, I have the following data: 2860377|"DATA1"|"DATA2"|"65343"|"DATA2"|"DATA4"|"11"|"DATA5"|"DATA6"|"65343"|"DATA7"|"0"|"8"|"1"|"NEGATIVE" 32340377|"DATA1"|"DATA2"|"65343"|"DATA2"|"DATA4"|"11"|"DATA5"|"DATA6"|"65343"|"DATA7"|"0"|"8"|"1"|"NEG-DID"... (3 Replies)
Discussion started by: sdohn
3 Replies

7. Shell Programming and Scripting

Do replace operation and awk to sum multiple columns if another column has duplicate values

Hi Experts, Please bear with me, i need help I am learning AWk and stuck up in one issue. First point : I want to sum up column value for column 7, 9, 11,13 and column15 if rows in column 5 are duplicates.No action to be taken for rows where value in column 5 is unique. Second point : For... (12 Replies)
Discussion started by: as7951
12 Replies

8. Shell Programming and Scripting

awk script to append suffix to column when column has duplicated values

Please help me to get required output for both scenario 1 and scenario 2 and need separate code for both scenario 1 and scenario 2 Scenario 1 i need to do below changes only when column1 is CR and column3 has duplicates rows/values. This inputfile can contain 100 of this duplicated rows of... (1 Reply)
Discussion started by: as7951
1 Replies

9. UNIX for Beginners Questions & Answers

Replace a numeric values in a certain column

Hi All, I am trying to replace a certain value from one place in a file . In the below file at position 35 I will have 8 I need to modify all 8 in that position to 7 I tried awk '{gsub("8","7",$35)}1' infile > outfile ----> not working sed -i 's/8/7'g' infile --- it is replacing all... (3 Replies)
Discussion started by: arunkumar_mca
3 Replies

10. UNIX for Beginners Questions & Answers

awk script to extract a column, replace one of the header and replace year(from ddmmyy to yyyy)

I have a csv which has lot of columns . I was looking for an awk script which would extract a column twice. for the first occurance the header and data needs to be intact but for the second occurance i want to replace the header name since it a duplicate and extract year value which is in ddmmyy... (10 Replies)
Discussion started by: Kunalcurious
10 Replies
DB2_FIELD_SCALE(3)							 1							DB2_FIELD_SCALE(3)

db2_field_scale - Returns the scale of the indicated column in a result set

SYNOPSIS
int db2_field_scale (resource $stmt, mixed $column) DESCRIPTION
Returns the scale of the indicated column in a result set. PARAMETERS
o $stmt - Specifies a statement resource containing a result set. o $column - Specifies the column in the result set. This can either be an integer representing the 0-indexed position of the column, or a string containing the name of the column. RETURN VALUES
Returns an integer containing the scale of the specified column. If the specified column does not exist in the result set, db2_field_scale(3) returns FALSE. SEE ALSO
db2_field_display_size(3), db2_field_name(3), db2_field_num(3), db2_field_precision(3), db2_field_type(3), db2_field_width(3). PHP Documentation Group DB2_FIELD_SCALE(3)
All times are GMT -4. The time now is 12:44 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy