Skip to main content
added 12 characters in body
Source Link
Kusalananda
  • 356.1k
  • 42
  • 737
  • 1.1k
awk -F, -vOFS=, '$2 ~ /\.app$/ { for (i = NF + 1; i > 2; --i) $i = $(i-1); $2 = "INVALID" } 1' file >newfile 

This would create newfile from file. The awk command sets both the input and output field delimiter to a comma, then tests the value of column two against a regular expression which matches the string .app at the end of the value. If the test succeeds, the record's fields are shifted right one step to make place for the string INVALID as the new second field.

The trailing 1 could be replaced by { print } (it causes every line to be outputted).

With the given example data, the output file would contain

DOM,PROJ,APP,USER,DATE,TIME,STATUS www,test,biz.app,bob,6-1-18,09:33,OK www,INVALID,biz.app,tony,7-11-17,06:22,ok 
awk -F, -vOFS=, '$2 ~ /\.app$/ { for (i = NF + 1; i > 2; --i) $i = $(i-1); $2 = "INVALID" } 1' file >newfile 

This would create newfile. The awk command sets both the input and output field delimiter to a comma, then tests the value of column two against a regular expression which matches the string .app at the end of the value. If the test succeeds, the record's fields are shifted right one step to make place for the string INVALID as the new second field.

The trailing 1 could be replaced by { print } (it causes every line to be outputted).

With the given example data, the output file would contain

DOM,PROJ,APP,USER,DATE,TIME,STATUS www,test,biz.app,bob,6-1-18,09:33,OK www,INVALID,biz.app,tony,7-11-17,06:22,ok 
awk -F, -vOFS=, '$2 ~ /\.app$/ { for (i = NF + 1; i > 2; --i) $i = $(i-1); $2 = "INVALID" } 1' file >newfile 

This would create newfile from file. The awk command sets both the input and output field delimiter to a comma, then tests the value of column two against a regular expression which matches the string .app at the end of the value. If the test succeeds, the record's fields are shifted right one step to make place for the string INVALID as the new second field.

The trailing 1 could be replaced by { print } (it causes every line to be outputted).

With the given example data, the output file would contain

DOM,PROJ,APP,USER,DATE,TIME,STATUS www,test,biz.app,bob,6-1-18,09:33,OK www,INVALID,biz.app,tony,7-11-17,06:22,ok 
Post Undeleted by Kusalananda
Post Deleted by Kusalananda
[Edit removed during grace period]; added 103 characters in body
Source Link
Kusalananda
  • 356.1k
  • 42
  • 737
  • 1.1k
awk -F, -vOFS=, '$2 ~ /\.app$/ { for (i = NF + 1; i > 2; --i) $i = $(i-1); $2 = "INVALID" } 1' file >newfile 

This would create newfile. The awk command sets both the input and output field delimiter to a comma, then tests the value of column two against a regular expression which matches the string .app at the end of the value. If the test succeeds, the field's value is setrecord's fields are shifted right one step to make place for the string INVALID as the new second field.

The trailing 1 could be replaced by { print } (it causes every line to be outputted).

With the given example data, the output file would contain

DOM,PROJ,APP,USER,DATE,TIME,STATUS www,test,biz.app,bob,6-1-18,09:33,OK www,INVALID,biz.app,tony,7-11-17,06:22,ok 
awk -F, -vOFS=, '$2 ~ /\.app$/ { $2 = "INVALID" } 1' file >newfile 

This would create newfile. The awk command sets both the input and output field delimiter to a comma, then tests the value of column two against a regular expression which matches the string .app at the end of the value. If the test succeeds, the field's value is set to the string INVALID.

The trailing 1 could be replaced by { print } (it causes every line to be outputted).

awk -F, -vOFS=, '$2 ~ /\.app$/ { for (i = NF + 1; i > 2; --i) $i = $(i-1); $2 = "INVALID" } 1' file >newfile 

This would create newfile. The awk command sets both the input and output field delimiter to a comma, then tests the value of column two against a regular expression which matches the string .app at the end of the value. If the test succeeds, the record's fields are shifted right one step to make place for the string INVALID as the new second field.

The trailing 1 could be replaced by { print } (it causes every line to be outputted).

With the given example data, the output file would contain

DOM,PROJ,APP,USER,DATE,TIME,STATUS www,test,biz.app,bob,6-1-18,09:33,OK www,INVALID,biz.app,tony,7-11-17,06:22,ok 
Source Link
Kusalananda
  • 356.1k
  • 42
  • 737
  • 1.1k

awk -F, -vOFS=, '$2 ~ /\.app$/ { $2 = "INVALID" } 1' file >newfile 

This would create newfile. The awk command sets both the input and output field delimiter to a comma, then tests the value of column two against a regular expression which matches the string .app at the end of the value. If the test succeeds, the field's value is set to the string INVALID.

The trailing 1 could be replaced by { print } (it causes every line to be outputted).