我有用于这里所描述的目的,有些简单的awk:awk只适用于复制的数据,为什么?
Append multiple header information fields to file until next header found
awk的仅适用于数据复制我/粘贴到一个新的文件之后。如果我将head的输出转换为新文件,那么awk仍然不起作用。 awk仅在将文件复制/粘贴到新文件时才有效。
`head -40 file.csv > output.csv`
这是AWK:
`awk -F, '/"Serial No."/ {sn = $2}
/"Location:"/ {loc = $2}
/"([0-9]{1,2}\/){2}[0-9]{4} [0-9]{2}:[0-9]{2}"/
{$0 = loc FS sn FS $0}1' file.csv>master1.csv`
如果我复制/粘贴数据,并将其与原始数据,输出指示在每一行有差别,但不说在哪里。如果你看一个头输出和复制/粘贴文件之间的差异,你可以:
`diff trap4_top.csv trap4_again.csv'
:
< 1,25c1,24
< "Serial No.","0700000036022821"
< "Location:","LS_trap_2c"
< "High temperature limit (�C)",20
< "Low temperature limit (�C)",0
< "Date - Time","Temperature (�C)"
< "5/28/2015 08:00",24.0
< "5/28/2015 10:00",29.5
< "5/28/2015 12:00",28.0
< "5/28/2015 14:00",28.5
< "5/28/2015 16:00",27.0
< "5/28/2015 18:00",24.5
< "5/28/2015 20:00",23.0
< "5/28/2015 22:00",22.5
< "5/29/2015 00:00",21.5
< "5/29/2015 02:00",21.0
< "5/29/2015 04:00",20.0
< "5/29/2015 06:00",20.0
< "5/29/2015 08:00",24.5
< "5/29/2015 10:00",26.0
< "5/29/2015 12:00",27.5
< "5/29/2015 14:00",30.0
< "5/29/2015 16:00",29.0
< "5/29/2015 18:00",25.5
< "5/29/2015 20:00",23.5
< "5/29/2015 22:00",23.0
---
> "Serial No.","0700000036022821"
> "Location:","LS_trap_2c"
> "High temperature limit (°C)",20
> "Low temperature limit (°C)",0
> "Date - Time","Temperature (°C)"
> "5/28/2015 08:00",24.0
> "5/28/2015 10:00",29.5
> "5/28/2015 12:00",28.0
> "5/28/2015 14:00",28.5
> "5/28/2015 16:00",27.0
> "5/28/2015 18:00",24.5
> "5/28/2015 20:00",23.0
> "5/28/2015 22:00",22.5
> "5/29/2015 00:00",21.5
> "5/29/2015 02:00",21.0
> "5/29/2015 04:00",20.0
> "5/29/2015 06:00",20.0
> "5/29/2015 08:00",24.5
> "5/29/2015 10:00",26.0
> "5/29/2015 12:00",27.5
> "5/29/2015 14:00",30.0
> "5/29/2015 16:00",29.0
> "5/29/2015 18:00",25.5
> "5/29/2015 20:00",23.5`
我看到特殊字符的差异,但我不是,如果他们涉及到,或者到目前为止如何删除它们,除了复制/粘贴。
head trap4.csv | cat -vte
给出:
"Serial No.","0700000036022821"^M$
"Location:","LS_trap_2c"^M$
"High temperature limit (M-0C)",20^M$
"Low temperature limit (M-0C)",0^M$
"Date - Time","Temperature (M-0C)"^M$
"5/28/2015 08:00",24.0^M$
"5/28/2015 10:00",29.5^M$
"5/28/2015 12:00",28.0^M$
"5/28/2015 14:00",28.5^M$
"5/28/2015 16:00",27.0^M$
显示输出| cat -vte' – anubhava
完成。它显示我怀疑是回车 – 5r9n