Unix - combine all rows into a comma-separated single row

后端 未结 2 1064
逝去的感伤
逝去的感伤 2021-02-06 19:42

I have following values in a file in separate lines:
California
New York
Washington
South Carolina
Kansas

What would be unix script to disp

2条回答
  •  执笔经年
    2021-02-06 20:00

    Use this command tr '\n' ',' < input_file

    For single quotes use sed -e "s/^/'/" input_file | sed -e "s/$/'/" | tr '\n' ','

    (Not tested for single/double quote escaping issues)

    For variable NEW_VAR=$(echo $VAR | sed -e "s/^/'/" | sed -e "s/$/'/" | tr '\n' ',')

提交回复
热议问题