Input format :
"130234":"f",
"130235":"m",
"130236":"f",
"130237":"f",
I want convert the above input from file to below output using awk command. 1. truncate the last "," and enclose with curly brace. Can any one help me on this.
{"130234":"f",
"130235":"m",
"130236":"f",
"130237":"f"}
You should use sed
for such trivial substitution:
$ sed '1s/^/{/;$s/,$/}/' file
{"130234":"f",
"130235":"m",
"130236":"f",
"130237":"f"}
Through awk,
$ awk 'BEGIN{printf "{"}{if (a) print a; a=$0}END{sub(/,$/, "}");print}' file
{"130234":"f",
"130235":"m",
"130236":"f",
"130237":"f"}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.