Sponsored Content
Full Discussion: Replace values
Top Forums Shell Programming and Scripting Replace values Post 302935855 by RudiC on Thursday 19th of February 2015 04:03:33 PM
Old 02-19-2015
Trying to understand your request, I found it doesn't fit the samples:
Code:
X  4714     14710  69445.00  19257.001 1218 12271  69596.00  19460.00  19478.001
                                            ^^^^----------------------------------(substr$0,45,4)-1
                                                                       ^^^^^------(substr$0,72,5)+2
X  4714     14710  69445.00  19257.001 1228 12292  69596.00  19480.00  19480.001
                                                ^---------------------------------if == 2
                                       ^^^^---------------------------------------(substr$0,40,4)+1 
                                                ^---------------------------------(substr$0,49,1)-1  
                                                             ^^^^^----------------(substr$0,62,5)+12

X  4714     14710  69445.00  19257.001 1218 12281  69596.00  19460.00  19480.001
                                            NNNN                       YYYYY 
X  4714     14710  69445.00  19257.001 1229 12291  69608.00  19480.00  19480.001
                                       YYYY     Y    NNN     NNNNN

"Y" indicates "might work"; "N" "doesn't"

Looks like you are overcomplicating things. Why working on characters and substrings? Can't you define it in, say, awk fields? Like if ($7 ~ /2$/) $7+=10, and so on?

---------- Post updated at 22:03 ---------- Previous update was at 20:08 ----------

Please check if the logics deliver what you need; I took into account your input and output samples, not your verbalized request. You can easily adapt that if need be. Formatting according to your input file will take another exercise and is left to you...
Code:
awk     '               {T[NR%2]=$0}
         $7 ~ /2$/      {$6 +=1; $7-=1; $8+=12  
                         T[NR%2]=$0
                         $0=T[(NR+1)%2]
                         $7+=10; $10+=2
                         T[(NR+1)%2]=$0
                        }
                        {print T[(NR+1)%2]}
         END            {print T[NR%2]}
        ' OFS="  " CONVFMT="%.3f" file4
X  4714  14710  69445.00  19257.001  1218  12281  69596.00  19460.00  19480.001
X  4714  14710  69445.00  19257.001  1229  12291  69608  19480.00  19480.001

This User Gave Thanks to RudiC For This Post:
 

10 More Discussions You Might Find Interesting

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

2. Web Development

Replace xml values

Hallo all, I try to create a bash script but till now without any positiv results. The script should replace different variables in a text file with the right xml values Look at the following xml file: file.xml =================================== <?xml version="1.0"... (1 Reply)
Discussion started by: research3
1 Replies

3. UNIX for Dummies Questions & Answers

using sed to replace values...

I have a file: $somevar=somevalue $anothervar= $someothervar=45 I'd like to be able to replace the values in the file. I just don't know how exactly to use sed. I was thinking along the lines of: cat file | sed "s/$somevar=/anotherval/g" I was hoping this would make the... (2 Replies)
Discussion started by: mrwatkin
2 Replies

4. Shell Programming and Scripting

Find and replace many values

Dear Friends, I did the same question before in other thread, but I want to explain a little better my request. I am looking for a way how to find and replace a values in two files using a reference a file where are the key to replace. Basically, I want to keep a copy of the original file... (1 Reply)
Discussion started by: jiam912
1 Replies

5. Shell Programming and Scripting

Replace values between 2 files

I want to replace the third and fourth lines of a 2nd file by the first two lines of a file. Input: file_1 file_1.line_1 file_1.line_2 file_2 file_2.line_1 <file_2.line_2_blank> file_2.line_3 file2.line_4 <file_2.line_5_blank> Output: file_2.line1 <file_2.line_2_blank>... (1 Reply)
Discussion started by: arpagon
1 Replies

6. Shell Programming and Scripting

Replace values in columns

I have the following input format: AA00000712000 -0.17 0.90 -1.04 -0.37 -1.45 -1.13 -0.22 -0.34 -0.55 2.37 0.67 -0.48 -0.48 AA00000712001 0.15 0.03 0.47 0.62 2.04 1.14 0.29 -0.81 0.85 0.53 1.00 -0.10 -0.48 BB00000712000 1.32 -0.47 0.44 0.00 0.98 ... (4 Replies)
Discussion started by: ncwxpanther
4 Replies

7. Shell Programming and Scripting

Replace values

Gents, Can you please help with this. Input file 49955 2009 2 49957 2010 2 49959 2010 2 49961 2010 2 49963 2010 2 49789 2011 -174 49791 2011 2 49793 2011 2 49795 2011 2 49965 2011 170 49967 2011 2 49969 2011 2 49971 2011 2 49797 2012 -174 49799 2012 2 (8 Replies)
Discussion started by: jiam912
8 Replies

8. Shell Programming and Scripting

Replace values using other file

Gents, Please can you help me. I need to update file1 using file2 values file1 S 44519.00 49349.00 1V1 0.0 0 0.0 0.0 0.0 0.0289091513 S 44513.00 48581.00 1V1 0.0 0 0.0 0.0 0.0 0.0289094319 S 44511.00 48605.00 1V1 0.0 0 0.0... (1 Reply)
Discussion started by: jiam912
1 Replies

9. Shell Programming and Scripting

To transpose and replace the values

Hi Guys, I am having a file like below AZ_H,NZ_K,IN_F,AZ1_A output required AZ_H string, NZ_K int, IN_F int, AZ1_A double the values will starting like below _A - double _F - int _H - string _K - int (6 Replies)
Discussion started by: rohit_shinez
6 Replies

10. Shell Programming and Scripting

Replace values on file

Gents, Please i need your help. Using the file2.txt i will like to replace values in file3.txt. Example in file 2 column 1 is the value to find in file3.txt and replace with value in colunm2 (file2.txt). Example file2.txt 21 1209 22 1210file3.txt SCI TB Timestamp Local : 8/30/17... (2 Replies)
Discussion started by: jiam912
2 Replies
Perl::Critic::Policy::BuiltinFunctions::ProhibitLvalueSuUser(Contributed Perl DocPerl::Critic::Policy::BuiltinFunctions::ProhibitLvalueSubstr(3pm)

NAME
Perl::Critic::Policy::BuiltinFunctions::ProhibitLvalueSubstr - Use 4-argument "substr" instead of writing "substr($foo, 2, 6) = $bar". AFFILIATION
This Policy is part of the core Perl::Critic distribution. DESCRIPTION
Conway discourages the use of "substr()" as an lvalue, instead recommending that the 4-argument version of "substr()" be used instead. substr($something, 1, 2) = $newvalue; # not ok substr($something, 1, 2, $newvalue); # ok The four-argument form of "substr()" was introduced in Perl 5.005. This policy does not report violations on code which explicitly specifies an earlier version of Perl (e.g. "use 5.004;"). CONFIGURATION
This Policy is not configurable except for the standard options. SEE ALSO
"substr" in perlfunc (or "perldoc -f substr"). "4th argument to substr" in perl5005delta AUTHOR
Graham TerMarsch <graham@howlingfrog.com> COPYRIGHT
Copyright (c) 2005-2011 Graham TerMarsch. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2012-06-07 Perl::Critic::Policy::BuiltinFunctions::ProhibitLvalueSubstr(3pm)
All times are GMT -4. The time now is 06:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy