我使用此命令
awk -F";" '{ print $0 "VVVVVVVV" $10 }' FILE3.csv
此打印效果不错,但按此顺序打印
VVVVVVVV; column10;的列1;列2;栏3:column4; column5 ..... column10
我需要反向打印 的列1;列2;栏3:column4; column5 ..... column10 ; VVVVVVVV; column10
但是我的工作怎么办?
答案 0 :(得分:0)
要么
$ awk -F";" '{ sub("\r",""); print $0 "VVVVVVVV" $10 }' file
或强>
$ awk -F";" '{ print $0 "VVVVVVVV" $10 }' RS="\r\n" file
或强>
$ dos2unix file
$ awk -F";" '{ print $0 "VVVVVVVV" $10 }' file
以下是示例
akshay@db-3325:/tmp$ cat file
column1;column2;column3;column4;column5;column6;column7;column8;column9;column10
column1;column2;column3;column4;column5;column6;column7;column8;column9;column10
# See at the end there is ^M char
akshay@db-3325:/tmp$ cat -A file
column1;column2;column3;column4;column5;column6;column7;column8;column9;column10^M$
column1;column2;column3;column4;column5;column6;column7;column8;column9;column10^M$
# Using awk without sub() - This is what you got
akshay@db-3325:/tmp$ awk -F";" '{ print $0 "VVVVVVVV" $10 }' file
VVVVVVVVcolumn10column3;column4;column5;column6;column7;column8;column9;column10
VVVVVVVVcolumn10column3;column4;column5;column6;column7;column8;column9;column10
# Using awk with sub() - This is what you wanted to get
akshay@db-3325:/tmp$ awk -F";" '{ sub("\r",""); print $0 "VVVVVVVV" $10 }' file
column1;column2;column3;column4;column5;column6;column7;column8;column9;column10VVVVVVVVcolumn10
column1;column2;column3;column4;column5;column6;column7;column8;column9;column10VVVVVVVVcolumn10
akshay@db-3325:/tmp$ awk -F";" '{ print $0 "VVVVVVVV" $10 }' RS="\r\n" file
column1;column2;column3;column4;column5;column6;column7;column8;column9;column10VVVVVVVVcolumn10
column1;column2;column3;column4;column5;column6;column7;column8;column9;column10VVVVVVVVcolumn10
# dos2unix
akshay@db-3325:/tmp$ dos2unix file
dos2unix: converting file file to Unix format ...
# Now you can see ^M is not there
akshay@db-3325:/tmp$ cat -A file
column1;column2;column3;column4;column5;column6;column7;column8;column9;column10$
column1;column2;column3;column4;column5;column6;column7;column8;column9;column10$
# Now your awk
akshay@db-3325:/tmp$ awk -F";" '{ print $0 "VVVVVVVV" $10 }' file
column1;column2;column3;column4;column5;column6;column7;column8;column9;column10VVVVVVVVcolumn10
column1;column2;column3;column4;column5;column6;column7;column8;column9;column10VVVVVVVVcolumn10