如何双引号添加到使用SED或AWK行? [英] How to add double quotes to a line with SED or AWK?

查看:138
本文介绍了如何双引号添加到使用SED或AWK行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个单词列表

name,id,3

我需要把它双引号括起来像这样

I need to have it double quoted like this

"name,id,3"

我已经试过SED的/.*/\\\"&放大器; \\/ G',得到了

I have tried sed 's/.*/\"&\"/g', got

"name,id,3

只有一个双引号

我也试过AWK {打印\\$ 1\\},具有完全相同的结果
需要帮助

I've also tried awk {print "\""$1"\""}, with exactly same result Need help

推荐答案

您输入的文件具有行的末尾回车。您需要使用 DOS2UNIX的上的文件将其删除。或者,你可以这样做:

Your input file has carriage returns at the end of the lines. You need to use dos2unix on the file to remove them. Or you can do this:

sed 's/\(.*\)\r/"\1"/g'

这将删除回车并添加引号。

which will remove the carriage return and add the quotes.

这篇关于如何双引号添加到使用SED或AWK行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆