Modifications to a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Modifications to a file
# 1  
Old 05-01-2012
Modifications to a file

I have a file whose format is shown below. It has a table of numbers. In this case, I have 16 values in 12 rows.

I want to select a position in the table, example, the 5th number at row 5. I need to change the value in that position by a certain amount and output the file with the modifiation.

Code:
% XI=(0,-0.5)
% XF=(80,30)

%< LAYER 1

% INTI=LIN
%( INTERFACE
0 0
80 0
%)

% PS=OFF

% INTP=LIN
%( MODELP
0.539195 0.499185 0.44318 0.420795 0.428972 0.407489 0.416661 0.396913 0.396623 0.406523 0.414327 0.4175 0.421689 0.439757 0.532754 0.639871 
0.958519 0.949427 0.91807 0.909091 0.921724 0.853104 0.809542 0.826688 0.818666 0.818959 0.850298 0.927109 0.91142 0.895533 0.963707 1.0135 
1.39397 1.36207 1.31659 1.35339 1.3523 1.2593 1.2001 1.21804 1.20746 1.19825 1.26995 1.35578 1.35353 1.3436 1.35959 1.3617 
1.83863 1.79101 1.75435 1.78663 1.82813 1.76773 1.68538 1.67378 1.66626 1.67004 1.7663 1.82656 1.83235 1.82628 1.78751 1.78362 
2.2295 2.225 2.19439 2.25352 2.28417 2.28628 2.20701 2.20558 2.19025 2.21139 2.25812 2.26599 2.28262 2.26116 2.25146 2.21499 
2.62044 2.63175 2.58642 2.61448 2.66013 2.62454 2.63246 2.61672 2.60205 2.59614 2.62228 2.63382 2.64696 2.66988 2.6161 2.56025 
2.99931 2.95359 2.92076 2.89449 2.90146 2.9228 2.95267 2.94976 2.94918 2.94359 2.98141 2.98476 2.98086 2.97434 2.89634 2.89142 
3.34278 3.2937 3.21962 3.20083 3.17678 3.22456 3.26254 3.27324 3.26747 3.27395 3.2762 3.29426 3.2832 3.24564 3.22182 3.18713 
3.58525 3.56012 3.51039 3.51268 3.48492 3.49081 3.49647 3.51275 3.53483 3.52009 3.51921 3.53977 3.53447 3.51355 3.5001 3.45128 
3.82946 3.8293 3.77809 3.78202 3.77015 3.77801 3.74097 3.74021 3.77757 3.80818 3.79032 3.75711 3.78332 3.77289 3.7477 3.73956 
4.13013 4.07422 4.04127 4.03045 4.02955 4.00759 3.98444 3.98823 4.00529 4.02987 4.03192 3.99721 3.99899 3.98829 3.9902 3.99331 
4.38031 4.3538 4.32092 4.29449 4.31182 4.26834 4.20803 4.20388 4.23141 4.26625 4.25487 4.24072 4.23403 4.2237 4.23338 4.22982 
%)

%>

# 2  
Old 05-01-2012
Does the table always start with %( MODELP?
# 3  
Old 05-01-2012
Yes it does.
# 4  
Old 05-01-2012
Try:
Code:
awk -vx=5 -vy=2 -vv=0 '/%\( MODELP/{i=0;t=1}/%)/{t=0}t&&i==y{$x=v}t{i++}1' file

x is column number, y is row number, v is value.
# 5  
Old 05-01-2012
I have tried it on an example and works well
Code:
awk -vx=5 -vy=2 -vv=0 '/%\( MODELP/{i=0;t=1}/%)/{t=0}t&&i==y{$x=300}t{i++}1' ngtv10-z30-dsr65-terr0.25-varp0.03-16x12drw.cmod

And I am getting
Code:
% XI=(0,-0.5)
% XF=(80,30)

%< LAYER 1

% INTI=LIN
%( INTERFACE
0 0
80 0
%)

% PS=OFF

% INTP=LIN
%( MODELP
0.538164 0.502978 0.471891 0.444607 0.436576 0.418319 0.406722 0.413201 0.406912 0.401163 0.419975 0.43507 0.431868 0.461941 0.548427 0.647139 
0.969733 0.935062 0.909421 0.903975 300 0.855065 0.815415 0.810692 0.814035 0.821854 0.853249 0.905094 0.900147 0.899454 0.952343 1.02236
1.40259 1.35929 1.31544 1.33006 1.34219 1.2993 1.22681 1.20605 1.2049 1.22852 1.28935 1.35766 1.35088 1.35311 1.34783 1.35564 
1.82205 1.79035 1.75477 1.77579 1.8162 1.77815 1.69619 1.68061 1.67708 1.68715 1.76351 1.81239 1.81766 1.81257 1.79736 1.76969 
2.23355 2.21797 2.21435 2.25217 2.28496 2.267 2.20563 2.18267 2.17404 2.20534 2.22842 2.25982 2.26517 2.27042 2.24397 2.22261 
2.6287 2.61411 2.58731 2.60675 2.64036 2.62373 2.6123 2.59683 2.59283 2.59872 2.62963 2.64247 2.64416 2.65761 2.61436 2.57318 
3.0115 2.9663 2.91521 2.90382 2.898 2.93671 2.95868 2.95502 2.94576 2.94257 2.97483 2.9847 2.98746 2.97102 2.90555 2.89862 
3.34594 3.28567 3.22011 3.20236 3.17731 3.22349 3.26719 3.27734 3.2722 3.267 3.28416 3.28997 3.27263 3.24995 3.22408 3.2036 
3.58738 3.55493 3.5097 3.50047 3.48325 3.48845 3.5052 3.51784 3.53272 3.53434 3.5308 3.53283 3.53137 3.51853 3.50103 3.45927 
3.84537 3.82063 3.78754 3.76429 3.76248 3.7592 3.74569 3.75114 3.78828 3.79501 3.78413 3.77144 3.78464 3.77875 3.75382 3.74069 
4.12285 4.06979 4.03994 4.04166 4.03971 4.01104 3.97258 3.98838 4.01396 4.03418 4.01292 4.00412 4.00931 3.99431 3.99493 3.99276 
4.38046 4.34633 4.32441 4.30317 4.30918 4.26445 4.20509 4.195 4.23101 4.25913 4.25346 4.24211 4.22984 4.22966 4.22939 4.23604 
%)

%>

I want to have a value, example 12.5 and want to add this value to the value that occurs at that position.
# 6  
Old 05-01-2012
Then try this:
Code:
awk -vx=5 -vy=2 -vv=12.5 '/%\( MODELP/{i=0;t=1}/%)/{t=0}t&&i==y{$x+=v}t{i++}1' ngtv10-z30-dsr65-terr0.25-varp0.03-16x12drw.cmod

This User Gave Thanks to bartus11 For This Post:
# 7  
Old 05-01-2012
Works great. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sentence delimiter in perl: modifications needed

Hello, I found this Perl Script on the EuroParl website which does Sentence Splitting. #!/usr/bin/perl -w # Based on Preprocessor written by Philipp Koehn binmode(STDIN, ":utf8"); binmode(STDOUT, ":utf8"); binmode(STDERR, ":utf8"); use FindBin qw($Bin); use strict; my $mydir =... (0 Replies)
Discussion started by: gimley
0 Replies

2. Shell Programming and Scripting

Modifications using Lookup file

I have 2 files. File 1 delimited by ";" File 1: 001;0;11223;xx;N;1001051;124;1;1;1001051;110;0;A_15;D;DX;U 001;0;8830943;xx;P;1226040;978;1;0;1226040;110;0;A_15;D;DX;H 001;0;10946903;xx;N;1300496;978;1;1;1300496;110;0;A_17;D;DX;H... (2 Replies)
Discussion started by: pparthiv
2 Replies

3. Shell Programming and Scripting

Modifications to a file

Hi, I do not have a clue how to do this nor can I find information on it but I have a file that looks like this (basically 3 columns and tab delimited). I need this in a particular format in order for a program to actually read it. chr1 2 4 chr1 2 5 chr1 3 6 chr2 1 4 chr2 2 5 ... (2 Replies)
Discussion started by: kylle345
2 Replies

4. Shell Programming and Scripting

XML file modifications using sed

Hi, During an installation process in a bash script I need to do 2 things with 2 XML files. Does the use of sed affect in any way the XML file ? 1.Add to a section in <ServerListeners> section <ServerListener> <BaseClass>myapp.module.WowConfigurator</BaseClass> </ServerListener> The... (2 Replies)
Discussion started by: potro
2 Replies

5. Shell Programming and Scripting

how to write modifications in to two tables

hi, how to write modifictions of two tables in the ksh (0 Replies)
Discussion started by: naveeng.81
0 Replies

6. Shell Programming and Scripting

question about testing in shell programming(modifications were made)

In folder A i have a file "a' and text file named infile00.I would like to do redirection :a<infile01. There is a code to do this #get a file "a" in /home/A for file in /home/A/* do if $file ] then #printing out if file is an execute file echo $file "is an... (2 Replies)
Discussion started by: thungmail
2 Replies

7. Shell Programming and Scripting

my shell script (file modifications)

hi guys Need some help on my below script #!/bin/sh if then echo "~~:S:wait:/sbin/sulogin" >> /root/joy/inittab else echo "/root/joy/inittab does not exist" fi now the problem is that when i run the above script it runs successfully but when i run it repeatedly the word echo... (2 Replies)
Discussion started by: whizkidash
2 Replies

8. UNIX for Dummies Questions & Answers

list files with modifications <15 minutes

Good Afternoon Guys: we can use ls -l to find out the files and their modification time. however, how to list the files say which are modified 15 minutes before. we have find command which uses -mtime and -atime for modification and access timing. However, if we just be restricted to the current... (2 Replies)
Discussion started by: tom_k_mishra
2 Replies

9. UNIX for Advanced & Expert Users

Tracing file modifications

Hello all! Is there a way or a utility to trace any kind of file changes in a particular directory on any UNIX machine? The purpose is that in Unix, there are multiple ways of opening and making changes to a file. But internally, there must be something common (a single pipe, etc.) that is... (3 Replies)
Discussion started by: gupta_ca
3 Replies

10. Shell Programming and Scripting

In Line File Modifications: Search and Replace

grep -il "TEST" ${ENVIRON}/*.pde| while read pde &nbsp;&nbsp;do &nbsp;&nbsp;&nbsp;&nbsp;cat $pde | sed s/"TEST 3,1"/"TEST 3,0"/g | sed s/"TEST&nbsp;&nbsp;3,1"/"TEST&nbsp;&nbsp;3,0"/g > ${pde}.tmp &nbsp;&nbsp;&nbsp;&nbsp;if ; then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mv ${pde}.tmp $pde ... (2 Replies)
Discussion started by: Shakey21
2 Replies
Login or Register to Ask a Question