Find in first column and replace the line with Awk, and output new file

Find in first column and replace the line with Awk, and output new file

File1.txt

"2011-11-02","Georgia","Atlanta","x","",""
"2011-11-03","California","Los Angeles","x","",""
"2011-11-04","Georgia","Atlanta","x","x","x"
"2011-11-05","Georgia","Atlanta","x","x",""    
"2011-11-06","Georgia","Atlanta","x","",""
"2011-11-07","Rhode Island","Providence","x","",""

***OUTPUT***
Result.txt

"2011-11-02","Georgia","Atlanta","x","",""
"2011-11-03","California","Los Angeles","x","",""
"2011-11-04","Georgia","Atlanta","x","x","x"
"2011-11-05","Georgia","Atlanta","x","x","x"
"2011-11-06","Georgia","Atlanta","x","",""
"2011-11-07","Rhode Island","Providence","x","",""

I am looking for 2011-11-05 in File1.txt, and I want to put an x on the 6th column. I figure we can use awk to find 2011-11-05, and replace the row with:
"2011-11-05","Georgia","Atlanta","x","x","x" an output a new Result.txt file

Also another awk script, to find 2011-11-03, put an x on the 5th and 6th column.
"2011-11-03","California","Los Angeles","x","x","x"

Thank you.

awk '/2011-11-05/ {$6=$5}1' FS=, OFS=, File1.txt

You can refer it to finish your second request.

1 Like

Thanks so much!!

So for the second it would be.

awk '/2011-11-03/ {$5=$4; $6=$4}1' FS=, OFS=, File1.txt

It works, just need to confirm this is the correct syntax with a semicolon?

; too run two commands

You are right!...

--ahamed

1 Like

Thanks.

I am learning. Thanks for rdcwayx and ahamed101 for being a great teacher!

By the way Ahamed, I am still testing the last code you gave me. It all works perfect! I will post as soon as it goes into production.

Thanks Again!