temp44
temp44

Reputation: 35

Add curly braces at beginning and end of column with awk

I want to add a set of curly braces to the entire fifth column of a log file to prepare it for storage in a DB.

Log file:

45324342342 192.168.0.10 10.0.2.15 www.example.com {8.8.8.8,8.8.4.4} 95

So far I've only been able to add it to the end of the column with:

awk '$5=$5"}"' file

I'm not sure how to reference the start of a column.

Upvotes: 0

Views: 1272

Answers (1)

Sundeep
Sundeep

Reputation: 23687

$ # OP's attempt
$ echo '1 2 3 4 5 6 7' | awk '$5=$5"}"'
1 2 3 4 5} 6 7

$ # answer mentioned in comments
$ # 5th field is changed to concatenation of {, $5 and }
$ # $0 gets printed as resulting non empty string serves as true condition
$ echo '1 2 3 4 5 6 7' | awk '$5="{"$5"}"'
1 2 3 4 {5} 6 7

Upvotes: 1

Related Questions