Add value in specific field


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Add value in specific field
# 1  
Old 12-15-2014
Add value in specific field

Gents,

I have many files to change increasing 40000 in specific field.

Can you help me with a command with sed or awk to fix this problem.

Where the the field has Marker FDU. I need to add 40000 plus

example

Code:
Marker FDU          27152.00

Code:
Marker FDU          67152.00

I should keep the same format of the file.

Input.

Code:
Receiver            69296.00  19286.00  20488.00
Receiver            69308.00  19256.00  20488.00
Receiver            69320.00  19256.00  20488.00
Receiver            69332.00  19258.00  20488.00
Receiver            69344.00  19266.00  20488.00
Receiver            69356.00  19270.00  20488.00

Tape Format                     SEG-D r2.1 8058, Mfr 13, 428 v5.18;

Swath     Tape      Date        Line         Point                  File
1504      C04739    08/Dec/2014 69151.00     19289.00               9
                                69143.00     19249.00               1553

Tape No.            File list
C04739              9-92,94-106,108-373,375-432,434-523,525-546,548-638,640-668,
C04739              670-692,694-713,715-791,793-802,804-926,928-929,931-932,
C04739              934-1096,1098-1108,1111,1113-1220,1222-1269,1271,1273-1352,
C04739              1354,1356-1396,1398,1400-1411,1413-1418,1421-1516,1518-1553.

Point Type          Line        Point     FDU Serial Number
Marker FDU          27152.00    19250.00  3489455.
Marker FDU          27152.00    19300.00  3603046.
Marker FDU          27152.00    19350.00  8858801.
Marker FDU          27152.00    19400.00  1607798.
Marker FDU          27152.00    19450.00  9191722.
Marker FDU          27152.00    19500.00  3579985.
Marker FDU          27152.00    19550.00  8707764.
Marker FDU          27152.00    19600.00  2836028.
Marker FDU          27152.00    19650.00  1143438.
Marker FDU          27152.00    19700.00  9592173.

Output

Code:
Receiver            69308.00  19256.00  20488.00
Receiver            69320.00  19256.00  20488.00
Receiver            69332.00  19258.00  20488.00
Receiver            69344.00  19266.00  20488.00
Receiver            69356.00  19270.00  20488.00

Tape Format                     SEG-D r2.1 8058, Mfr 13, 428 v5.18;

Swath     Tape      Date        Line         Point                  File
1504      C04739    08/Dec/2014 69151.00     19289.00               9
                                69143.00     19249.00               1553

Tape No.            File list
C04739              9-92,94-106,108-373,375-432,434-523,525-546,548-638,640-668,
C04739              670-692,694-713,715-791,793-802,804-926,928-929,931-932,
C04739              934-1096,1098-1108,1111,1113-1220,1222-1269,1271,1273-1352,
C04739              1354,1356-1396,1398,1400-1411,1413-1418,1421-1516,1518-1553.

Point Type          Line        Point     FDU Serial Number
Marker FDU          67152.00    19250.00  3489455.
Marker FDU          67152.00    19300.00  3603046.
Marker FDU          67152.00    19350.00  8858801.
Marker FDU          67152.00    19400.00  1607798.
Marker FDU          67152.00    19450.00  9191722.
Marker FDU          67152.00    19500.00  3579985.
Marker FDU          67152.00    19550.00  8707764.
Marker FDU          67152.00    19600.00  2836028.
Marker FDU          67152.00    19650.00  1143438.
Marker FDU          67152.00    19700.00  9592173.

Thanks for your help
# 2  
Old 12-15-2014
Any attempts from your side?
# 3  
Old 12-15-2014
Till now nothing I am trying to do it with
gsub() but nothing good yet
# 4  
Old 12-15-2014
Try

Code:
awk '/Marker FDU/{$3+=40000}1'  infile

to keep same formatting try this

Code:
awk '/Marker FDU/{split($0,d,/[^[:space:]]*/);$3=sprintf("%5.2f",$3+40000);s="";for(i=1;i<=NF;i++)s=sprintf("%s%s%s",s,d[i],$i); $0 = s}1' infile

This User Gave Thanks to Akshay Hegde For This Post:
# 5  
Old 12-15-2014
Dear Akshay.

It works Perfect.

Thanks a lot for your help
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to update specific value in file with match and add +1 to specific digit

I am trying to use awk to match the NM_ in file with $1 of id which is tab-delimited. The NM_ will always be in the line of file that starts with > and be after the second _. When there is a match between each NM_ and id, then the value of $2 in id is substituted or used to update the NM_. Each NM_... (3 Replies)
Discussion started by: cmccabe
3 Replies

2. Shell Programming and Scripting

awk to add symbol to specific field

Trying to use awk to add a . to $4. The input and output is tab-delimeted, but the awk seems to add a . in front of $5 and is space-delimeted. It seems close, but I am not able to produce the desired output. Thank you :). file chr1 948895 949015 chr1:948895-949015 ISG15 chr1 ... (1 Reply)
Discussion started by: cmccabe
1 Replies

3. Shell Programming and Scripting

sed to add field heards to specific fields

I have tab delimited input that prints out in the format below: I am trying to add field headers to $5 and $6. Not sure if sed is the best tool but my attempt is below. Thank you :). $5 = REF $6 = ALT file ID CHR START STOP 123 1 100 200 A ... (6 Replies)
Discussion started by: cmccabe
6 Replies

4. Shell Programming and Scripting

Add specific string to last field of each line in perl based on value

I am trying to add a condition to the below perl that will capture the GTtag and place a specific string in the last field of each line. The problem is that the GT value used is not right after the tag rather it is a few fields away. The values should always be 0/1 or 1/2 and are in bold in the... (12 Replies)
Discussion started by: cmccabe
12 Replies

5. Shell Programming and Scripting

Add tab after digit in specific field in file

I am trying to add a tab after the last digit in $3 in the input. The grep below is all I can think off. Thank you :) sed -n 's/:/&/p' input input chr1 955542 955763AGRN-6|gc=75 chr1 957570 957852AGRN-7|gc=61.2 chr1 976034 976270AGRN-9|gc=74.5 desired output chr1... (5 Replies)
Discussion started by: cmccabe
5 Replies

6. Shell Programming and Scripting

How to print with awk specific field different from specific character?

Hello, i need help with awk. I have this file: cat number DirB port 67 er_enc_out 0 er_bad_os 0 DirB port 71 er_enc_out 56 er_bad_os 0 DirB port 74 er_enc_out 0 er_bad_os 0 DirB port 75 ... (4 Replies)
Discussion started by: elilmal
4 Replies

7. Shell Programming and Scripting

Add "1234" to specific field in second column

i have this file 073274753,0544901701,20101201,000316 038873722,69647455,20101130,235257 26213399,0545335767,20101201,000930 063330167,0566000101,20101201,000226 026773376,11966,20101130,234429,1194 075431120,0565900600,20101201,000428 75431120,0565900600,20101201,000538... (6 Replies)
Discussion started by: maxim42
6 Replies

8. Shell Programming and Scripting

Replace specific field on specific line sed or awk

I'm trying to update a text file via sed/awk, after a lot of searching I still can't find a code snippet that I can get to work. Brief overview: I have user input a line to a variable, I then find a specific value in this line 10th field in this case. After asking for new input and doing some... (14 Replies)
Discussion started by: crownedzero
14 Replies

9. Shell Programming and Scripting

Using awk to read a specific line and a specific field on that line.

Say the input was as follows: Brat 20 x 1000 32rf Pour 15 p 1621 05pr Dart 10 z 1111 22xx My program prompts for an input, what I want is to use the input to locate a specific field. Like if I type in, "Pou" then it would return "Pour" and just "Pour" I currently have this line but it is... (6 Replies)
Discussion started by: Bungkai
6 Replies

10. Shell Programming and Scripting

awk field equal something, then add something to the field

Hi Everyone, a.txt a b c 1 e e e e e a b c 2 e e e e e the output is a b c 1 e e e e e a 00b c 2 e e e e e when 4th field = '2', then add '00' in the front of 2nd field value. Thanks (9 Replies)
Discussion started by: jimmy_y
9 Replies
Login or Register to Ask a Question