How to do find and replace in one field based on the value in the other field?

M.Nehru

I have a file like this.

IMS00|20140101|Unix|Jan14
IMS01|20140201|Unix|Feb14
IMS02|20140301|Unix|Mar14
IMS03|20140101|Unix|Jan14
IMS04|20140201|Unix|Feb14

My criteria are, if the column 1 value is IMS00, then column 4 value Jan14 should be replaced with Jan15 if the column 1 value is IMS01, then column 4 value Feb14 should be replaced with Feb15.

How can this be done?

jimmij

Your question is not very clear, for example in the code you write IMS00 and later on refer to it as IMS.00, with dot. Also number of changed column should be probably 4, not 3. Anyway, you are probably looking for

awk 'BEGIN{FS=OFS="|"}$1=="IMS00"{$4="Jan15"}$1=="IMS01"{$4="Feb15"}1' file

The BEGIN block executes only once at the very beginning and sets both field separator FS and output field separator OFS to |. Final 1 is just to print everything.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

mongodb count value of one field based on other

From Dev

How to null values based on an other field value

From Dev

How do I need to modify this MERGE statement, for a mass update of one field based on the value of a field in another table?

From Dev

How to find documents where value exist in one field (product) but not in the other (companyName)...

From Dev

jQuery Validate: how do I validate based on other field's value?

From Dev

How to update field value based on other table in mySql?

From Dev

How to set django model field value based-on value of other field in the same Model

From Dev

how to set django model field value based on value of other field in the different model

From Dev

How to replace the value of field on another?

From Dev

Replace field in one file based on match with a different field in another file

From Dev

replace the content of one field based on the content in another field

From Dev

How to find all documents where the value of one field matches that of another

From Dev

How to delete rows based on field value but not if certain other field values Dont exist

From Dev

set field value based on other fields values

From Dev

set field value based on other fields values

From Dev

Joomla Component Dynamic Custom Field based on other Field Value

From Dev

how to copy one field input value to other field input using javascript

From Dev

Update value of one field based on another

From Dev

Inheriting a field value based on a different one

From Dev

Grouping samples based on value dependent on one field

From Dev

How to replace a particular field in a file based on the content of another field?

From Dev

How to replace a particular field in a file based on the content of another field?

From Dev

PHP foreach Two arrays, find a value in one, use a different field in the other (add to array)

From Dev

How to add conditional schema based on other field?

From Dev

javascript: How to print values from several buttons into one single text field (one value after the other)?

From Dev

Use Field_A value to find records based on a modified version of Field_A value on the same field

From Dev

awk replace field value based on matching value in another file

From Dev

How to replace value of an XML field using Ant?

From Dev

PostgreSQL: How to replace different value in the same field?

Related Related

  1. 1

    mongodb count value of one field based on other

  2. 2

    How to null values based on an other field value

  3. 3

    How do I need to modify this MERGE statement, for a mass update of one field based on the value of a field in another table?

  4. 4

    How to find documents where value exist in one field (product) but not in the other (companyName)...

  5. 5

    jQuery Validate: how do I validate based on other field's value?

  6. 6

    How to update field value based on other table in mySql?

  7. 7

    How to set django model field value based-on value of other field in the same Model

  8. 8

    how to set django model field value based on value of other field in the different model

  9. 9

    How to replace the value of field on another?

  10. 10

    Replace field in one file based on match with a different field in another file

  11. 11

    replace the content of one field based on the content in another field

  12. 12

    How to find all documents where the value of one field matches that of another

  13. 13

    How to delete rows based on field value but not if certain other field values Dont exist

  14. 14

    set field value based on other fields values

  15. 15

    set field value based on other fields values

  16. 16

    Joomla Component Dynamic Custom Field based on other Field Value

  17. 17

    how to copy one field input value to other field input using javascript

  18. 18

    Update value of one field based on another

  19. 19

    Inheriting a field value based on a different one

  20. 20

    Grouping samples based on value dependent on one field

  21. 21

    How to replace a particular field in a file based on the content of another field?

  22. 22

    How to replace a particular field in a file based on the content of another field?

  23. 23

    PHP foreach Two arrays, find a value in one, use a different field in the other (add to array)

  24. 24

    How to add conditional schema based on other field?

  25. 25

    javascript: How to print values from several buttons into one single text field (one value after the other)?

  26. 26

    Use Field_A value to find records based on a modified version of Field_A value on the same field

  27. 27

    awk replace field value based on matching value in another file

  28. 28

    How to replace value of an XML field using Ant?

  29. 29

    PostgreSQL: How to replace different value in the same field?

HotTag

Archive