Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ho do I perform action only IF = true

Status
Not open for further replies.

Tison

Programmer
May 12, 1999
216
CH
I need to update the following record only if the value of field 3 = a specified date.
My data
A|1|03/12/02|12:34|a lot of text
A|1|02/11/02|10:01|comments
C|7|03/12/02|12:30|text data

so IF FIELD 3 = 03/12/02 then MAKE FIELD 2 = x (where x = 8)
 
ok and what do you have so far?
vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
nawk -f update.awk file.txt

OR [with modified values to check/update]

nawk -v date2check=&quot;02/11/02&quot; -v value2update=&quot;5&quot; nawk -f update.awk file.txt

#-------------- update.awk
BEGIN {
FS=OFS=&quot;|&quot;
field2check=&quot;3&quot;
field2update=&quot;2&quot;

if (date2check == &quot;&quot;) date2check=&quot;03/12/02&quot;
if (value2update == &quot;&quot;) value2update=&quot;8&quot;
}

$field2check ~ date2check { $field2update = value2update }
1 vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top