[英]Remove double quotes from txt file
I have a file that contains unwanted double quotes around the column values. 我有一个文件,其中在列值周围包含不需要的双引号。 I need to remove them. 我需要删除它们。 Could someone help me on this? 有人可以帮我吗?
The data is in below format 数据格式如下
column1 date picture value
"A" "2016-06-02" "books" 932422 "B" "2016-06-03" "movies" 934735 "C" "2016-06-04" "vidoes" 936025 "D" "2016-06-05" "movies" 937620 "E" "2016-06-06" "dvd" 938972 "F" "2016-06-07" "vidoes" 940274
column1 date picture value
"A" "2016-06-02" "books" 932422 "B" "2016-06-03" "movies" 934735 "C" "2016-06-04" "vidoes" 936025 "D" "2016-06-05" "movies" 937620 "E" "2016-06-06" "dvd" 938972 "F" "2016-06-07" "vidoes" 940274
And I want to the data to be like: 我希望数据像这样:
column1 date picture value
A 2016-06-02 books 932422 B 2016-06-03 movies 934735 C 2016-06-04 vidoes 936025 D 2016-06-05 movies 937620 E 2016-06-06 dvd 938972 F 2016-06-07 vidoes 940274
column1 date picture value
A 2016-06-02 books 932422 B 2016-06-03 movies 934735 C 2016-06-04 vidoes 936025 D 2016-06-05 movies 937620 E 2016-06-06 dvd 938972 F 2016-06-07 vidoes 940274
Note that 4th column attribute do not have double quotes around them. 请注意,第4列属性周围没有双引号。
Could somebody help me with removing these double quotes with one line shell scripting? 有人可以帮我用一行shell脚本删除这些双引号吗?
tr -d '"' <infile
column1 date picture value
A 2016-06-02 books 932422
B 2016-06-03 movies 934735
C 2016-06-04 vidoes 936025
D 2016-06-05 movies 937620
E 2016-06-06 dvd 938972
F 2016-06-07 vidoes 940274
Or using awk
: 或使用awk
:
awk -F\" '{$1=$1}1' infile
column1 date picture value
A 2016-06-02 books 932422
B 2016-06-03 movies 934735
C 2016-06-04 vidoes 936025
D 2016-06-05 movies 937620
E 2016-06-06 dvd 938972
F 2016-06-07 vidoes 940274
or using sed
: 或使用sed
:
sed 's/"//g' infile
column1 date picture value
A 2016-06-02 books 932422
B 2016-06-03 movies 934735
C 2016-06-04 vidoes 936025
D 2016-06-05 movies 937620
E 2016-06-06 dvd 938972
F 2016-06-07 vidoes 940274
or using awk
's gsub
function: 或使用awk
的gsub
函数:
awk '{gsub(/"/,"")}1' infile
column1 date picture value
A 2016-06-02 books 932422
B 2016-06-03 movies 934735
C 2016-06-04 vidoes 936025
D 2016-06-05 movies 937620
E 2016-06-06 dvd 938972
F 2016-06-07 vidoes 940274
如果可以使用sed,
$ sed 's/\"//g' file.txt > file_new.txt
Just use the below command and run it on the file. 只需使用以下命令并在文件上运行它即可。 The file gets modified automatically. 该文件将自动修改。 No need for a temporary file for redirection. 不需要用于重定向的临时文件。
perl -pi -e 's/\"//g' infile
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.