Sponsored Content
Top Forums Shell Programming and Scripting awk how to replace specific field with new value Post 302511429 by freegnu on Wednesday 6th of April 2011 07:05:05 PM
Old 04-06-2011
This does it all. Remove parts to do one or the other.
Code:
awk '/^5/||(NR==2){for(i=1;i<=NF;i++)if($i=="x")$i="y";print $0};/^[^5]/&&(NR!=2)' input


Last edited by freegnu; 04-06-2011 at 08:23 PM.. Reason: I refactored it. My original version doesn't satisfy all of the criteria.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to replace particular field

i have bad data for instance, the use of capital letters in the middle of the word. I identified the errors, made a list and put it in a file error_correction.txt Incorrect,Correct VeNOM,Venom nos,NOS . . . My data file looks like this: vgr,bugatti veron,,3.5,Venom,6,.......,....... (14 Replies)
Discussion started by: VGR
14 Replies

2. Shell Programming and Scripting

Awk to replace a field

Hi I am using awk to replace the 4th feild of the input line. My code is below: REP_LINE=$(echo $Line | awk -v var=$REPL_DT '{$4=var; print}') It does replaces but all words/phrases after the 4th feild are erased. Is there a way to modify the 4th feild of the input line and to have all... (7 Replies)
Discussion started by: sugan
7 Replies

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

4. Shell Programming and Scripting

awk search/replace specific field, using variables for regexp & subsitution then overwrite file

Hello, I'm trying the solve the following problem. I have a file which I intend to use as a csv called master.csv The columns are separated by commas. I want to change the text on a specific row in either column 3,4,5 or 6 from xxx to yyy depending upon if column 1 matches a specified pattern.... (3 Replies)
Discussion started by: cyphex
3 Replies

5. Shell Programming and Scripting

AWK replace one field

I have some problem with this. Need to change field #3 to 5 if field #1 = A and filed #2 =B DataA C 6 T C B 4 R A B 3 T D E 5 4 I would like to do two things if statement is true, but can not get it to work. Here it prints column #3 if statement is true, and this works awk '{if... (3 Replies)
Discussion started by: Jotne
3 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. UNIX for Dummies Questions & Answers

How to replace and remove few junk characters from a specific field?

I would like to remove all characters starting with "%" and ending with ")" in the 4th field - please help!! 1412007819.864 /device/services/heartbeatxx 204 0.547%!i(int=0) 0.434 0.112 1412007819.866 /device/services/heartbeatxx 204 0.547%!i(int=1) 0.423 0.123... (10 Replies)
Discussion started by: snemuk14
10 Replies

8. Shell Programming and Scripting

awk to replace a specific field in certain condition

Hi, I have a file like below PRUM,67016800 ,CC ,C1,67016800 , ,Y,Y,2 ,CK,BX,FOX ,00000001,EA,00000001,20141120 00:00:00, ,N,Y,Y,CK ABCDEF... (7 Replies)
Discussion started by: mady135
7 Replies

9. Shell Programming and Scripting

awk - how to print specific field if a string is matched

hi gurus, I would like to be able to use awk to process 1 file as such: abc 1 2 3 4 5 6 7 8 9 10 flags 1 2 4 flags 1 2 5 abc 2 3 4 5 6 7 8 9 10 11 flags 1 2 3 abc 4 5 6 7 8 9 6 7 78 89 flags 1 2 3 flags 1 2 4 flags 1 2 3 4 I would like to be able to print field 1 and 5 when the... (4 Replies)
Discussion started by: revaroo
4 Replies

10. 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
CUBRID_RESULT(3)							 1							  CUBRID_RESULT(3)

cubrid_result - Return the value of a specific field in a specific row

SYNOPSIS
string cubrid_result (resource $result, int $row, [mixed $field]) DESCRIPTION
This function returns the value of a specific field in a specific row from a result set. PARAMETERS
o $result -$result comes from a call to cubrid_execute(3) o $row -The row number from the result that is being retrieved. Row numbers start at 0. o $field - The name or offset of the $field being retrieved. It can be the field's offset, the field's name, or the field's table dot field name (tablename.fieldname). If the column name has been aliased ('select foo as bar from...'), use the alias instead of the column name. If undefined, the first field is retrieved. RETURN VALUES
Value of a specific field, on success (NULL if value if null). FALSE on failure. EXAMPLES
Example #1 cubrid_result(3) example <?php $conn = cubrid_connect("localhost", 33000, "demodb"); $req = cubrid_execute($conn, "SELECT * FROM code"); $result = cubrid_result($req, 0); var_dump($result); $result = cubrid_result($req, 0, 1); var_dump($result); $result = cubrid_result($req, 5, "f_name"); var_dump($result); cubrid_close_request($req); cubrid_disconnect($conn); ?> The above example will output: string(1) "X" string(5) "Mixed" string(4) "Gold" PHP Documentation Group CUBRID_RESULT(3)
All times are GMT -4. The time now is 07:25 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy