Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Replace a numeric values in a certain column Post 303031041 by arunkumar_mca on Wednesday 20th of February 2019 10:02:38 PM
Old 02-20-2019
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
Code:
awk '{gsub("8","7",$35)}1' infile > outfile  ----> not working 
sed -i 's/8/7'g' infile --- it is replacing all the values  to 7 in the file.

infile:
020000492019010369200000000000000080009999005566005852006266004961000000000000000000000000
020000492019010369200012000809990080000021005566005852006266004961004100004615004490003951
020000492019010369200021131506450080000095005566005852006266004961004301006451006763006043
020000492019010369200033383653250080000121005566005852006266004961009473007622008426007768
020000492019010369200078000082160080000021005566005852006266004961004100004615004490003951
020000492019010369200078742014720080000021005566005852006266004961004100004615004490003951
020000492019010369200078742082950080000099005566005852006266004961002196002760003833002774
020000492019010369200078742104180080000099005566005852006266004961002196002760003833002774


Expected output:

020000492019010369200000000000000070009999005566005852006266004961000000000000000000000000
020000492019010369200012000809990070000021005566005852006266004961004100004615004490003951
020000492019010369200021131506450070000095005566005852006266004961004301006451006763006043
020000492019010369200033383653250070000121005566005852006266004961009473007622008426007768
020000492019010369200078000082160070000021005566005852006266004961004100004615004490003951
020000492019010369200078742014720070000021005566005852006266004961004100004615004490003951
020000492019010369200078742082950070000099005566005852006266004961002196002760003833002774
020000492019010369200078742104180070000099005566005852006266004961002196002760003833002774

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

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace spaces with 0's having numeric values.

What could be the regular expression with gsub function in awk to replace all numerics having spaces before to be replaced with 0s? (1 Reply)
Discussion started by: videsh77
1 Replies

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

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

4. UNIX for Dummies Questions & Answers

Find and Replace random numeric value with non-numeric value

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)
Discussion started by: Bahf1s
6 Replies

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

6. UNIX for Dummies Questions & Answers

replace a column with values from another file

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)
Discussion started by: chen.xiao.po
11 Replies

7. Shell Programming and Scripting

Splitting the numeric vs alpha values in a column to distinct columns

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)
Discussion started by: driftlogic
7 Replies

8. Shell Programming and Scripting

Replace column values from other file

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)
Discussion started by: samaritan
8 Replies

9. UNIX for Dummies Questions & Answers

Replace all decimal values in a column

Hi My input file looks String000002 GeneWise CW 48945 49354 . - 0 Pt=PEQU_00004; String000002 LEN NA 52125 52604 0.945751 - . PID=PEQU_00005;lvid_id=PEQ_28708; String000002 LEN CW 52125 52604 . - 0 ... (3 Replies)
Discussion started by: siya@
3 Replies

10. UNIX for Advanced & Expert Users

Sort by second column numeric values

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)
Discussion started by: cokedude
7 Replies
cdk_position(3) 					     Library Functions Manual						   cdk_position(3)

NAME
cdk_position - curses widget positioning key-bindings SYNOPSIS
Position methods for the Cdk widgets allow the user to move the widget around the screen via the cursor/keypad keys. DESCRIPTION
The following key bindings can be used to move the widget around the screen. +---------------------------------------------------------------+ |Key Action | +---------------------------------------------------------------+ |Up Arrow Moves the widget up one row. | |Down Arrow Moves the widget down one row. | |Left Arrow Moves the widget left one column | |Right Arrow Moves the widget right one column | |1 Moves the widget down one row and left one | | column. | |2 Moves the widget down one row. | |3 Moves the widget down one row and right one | | column. | |4 Moves the widget left one column | |5 Centers the widget both vertically and hori- | | zontally. | |6 Moves the widget right one column | |7 Moves the widget up one row and left one | | column. | |8 Moves the widget up one row. | |9 Moves the widget up one row and right one | | column. | |t Moves the widget to the top of the screen. | |b Moves the widget to the bottom of the | | screen. | |l Moves the widget to the left of the screen. | |r Moves the widget to the right of the screen. | |c Centers the widget between the left and | | right of the window. | |C Centers the widget between the top and bot- | | tom of the window. | |Escape Returns the widget to its original position. | |Return Exits the function and leaves the wid- | | getwhere it was. | +---------------------------------------------------------------+ +---------------------------------------------------------------+ The numbers 0-9 are chosen to correspond to the numeric keypad on your terminal. Cdk does not handle the application mode keypad control sequences, since those are not defined via terminfo. To use the numeric keypad you should ensure that it is in normal (or NumLock) mode. SEE ALSO
cdk(3), cdk_binding(3), cdk_display(3), cdk_screen(3) cdk_position(3)
All times are GMT -4. The time now is 03:58 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy