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
Also on a follow up if I want to replace 008 to 009 . 008 is on the same column 33-35. What should I do
Last edited by arunkumar_mca; 02-20-2019 at 11:18 PM..
Could you please try following once. This is specifically for 35th character's replacement.
I am using substring function of awk to get first 34 characters and then printing 7 along with rest of the characters of line.
Hi All,
..................................
Also on a follow up if I want to replace 008 to 009 . 008 is on the same column 33-35. What should I do
Hello arunkumar_mca,
Position of a character(s) is different from column number.
Example:
In above example if you talk in normal terms then position of a is 7 and it is NOT 7th column in that line.
Now question is when it becomes 7th column, let us think by default field separator is SPACE(I am talking about awk here). So your 7th position will be "called as " 7th field/column when field delimiter of awk is been set to NULL. Which is again a GNU awk function only. So please clear in your statements here.
Thanks,
R. Singh
Last edited by RavinderSingh13; 02-21-2019 at 12:56 AM..
Note that the code RavinderSingh13 suggested in post #2 in this thread will change the 35th character on every line; not just on lines where the original character in that position was "8".
For your second question you might want to try:
It wasn't at all clear whether you wanted to make both changes in the same input file. If you do, the order in which you process the changes is very important. If you perform the two operations in the order you specified, the change of "008" to "009" will never happen since the "8" will already have been changed to a "7".
If what you want is to change "008" in character positions 33 through 35 (with the first position on a line being character position 1) and if there is a "8" in character position 35 where at least one of the characters in positions 33 and 34 is not "0", then you might want to try:
And, as RavinderSingh13 already said, you need to tell us on every thread that you start what operating system and shell you're using. Both of the above scripts will work on most BSD, Linux, and UNIX operating systems, but will not work on Solaris/SunOS systems. On Solaris/SunOS systems, you'll need to change awk in both of the above scripts to either /usr/xpg4/bin/awk or nawk.
Last edited by Don Cragun; 05-21-2019 at 03:04 PM..
Reason: Fix tags on nawk: s/CODE/ICODE/g.
This User Gave Thanks to Don Cragun For This Post:
From googling and reading man pages I figured out this sorts the first column by numeric values.
sort -g -k 1,1
Why does the -n option not work? The man pages were a bit confusing.
And what if I want to sort the second column numerically? I haven't been able to figure that out. The file... (7 Replies)
I have one file as it has the following format
File1
S No Site IP Address
1 Australia 192.168.0.1/26
2 Australia 192.168.0.2/26
3 Australia 192.168.0.3/26
I need awk/sed command to replace the column2 value ( under Site) with some other... (8 Replies)
How could i take an input file and split the numeric values from the alpha values (123 vs abc) to distinc columns, and if the source is blank to keep it blank (null) in both of the new columns:
So if the source file had a column like:
Value:
|1 |
|2.3|
| |
|No|
I would... (7 Replies)
Dear all,
I have a file1.pdb in pdb format and a dat file2 containing values, corresponding to the atoms in the pdb file. these values (file2.dat) need to be in the column instead of the 0.00 (file1) values for each atom in file1.pdb .(the red values must be replaced by the blue ones,in order)... (11 Replies)
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)
Can someone tell me how to change the first column in a very large 17k line file from a random 10 digit numeric value to a non numeric value. The format of lines in the file is:
1702938475,SNU022,201004
the first 10 numbers always begin with 170 (6 Replies)
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)
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)