⼀维数据如何找出它的拐点_它的
⼀维数据如何找出它的拐点
回声$ title | d -e“ s / Sed- / El” (echo $title | d -e “s/Sed-/El”)
Linux is a wonderful tool. If you’ve never worked in it before, why not check it out? You can do it without dual-booting or tting up a Virtual Machine (well it’s like a VM, but different) with Docker. I wrote a tutorial about it in another post you can read here.
L inux是⼀个很棒的⼯具。 如果您以前从未使⽤过它,为什么不检查⼀下呢? 你能做到不与泊坞窗双启动或设置为V irtual 中号
achine(以及它就像⼀个虚拟机,但不同的)。 我在另⼀篇⽂章中写了⼀篇关于它的教程,您可以在这⾥阅读。
If you have ud Linux before, and you’ve found your way around the command line, you may have heard of a little tool called d. d stands for Stream Editor, and is extremely uful for text transformations on input streams.
如果您以前使⽤过Linux,并且已经在命令⾏中找到了⾃⼰的⽅式,那么您可能听说过⼀个名为d的⼩⼯具。 d代表S tream 编辑器 ,对于输⼊流中的⽂本转换⾮常有⽤。
Let’s explore the following scenario:
让我们探讨以下情形:
Your vendor has just shipped you a zipped file of asts with a text file referencing the zipped contents and reference files (so you are able to re-build the asts on your site internally). If the file was nt with Windows, but your build script only runs Linux files, there can be issues with the ‘\n\r’ carriage-newline return the end of each line. How would you fix this?
您的供应商刚刚向您发送了资产的压缩⽂件,其中包含引⽤了压缩后的内容和参考⽂件的⽂本⽂件(因此,您可以在内部站点上重建资产)。 如果⽂件是使⽤Windows发送的,但是您的构建脚本仅运⾏Linux⽂件,则'\ n \ r'回车换⾏符返回每⾏末尾可能会出现问题。
您将如何解决?
Another example:
另⼀个例⼦:
You noticed the CSV files you are about to nd your clients has the wrong time inrted. We’re talking, there's is over 400 sheets all with the incorrect date in all of them. This will throw off the client's calculations. How can you update them all and rewrite the updated correct date?
您注意到要发送给客户的CSV⽂件插⼊的时间错误。 我们正在说的是,有超过400张纸都带有错误的⽇期。 这将甩掉客户的计算。
如何更新它们并重写更新的正确⽇期?
How would we do this?
我们将如何做?
SED
SED
Photo by on
在 上的
Let’s take the above examples and break them down:
让我们以上述⽰例为例进⾏分解:
删除Windows回车 (Remove Windows Carriage-Return)
To remove the Windows Carriage-Return you simply build the following d command:
要删除Windows回车,您只需构建以下d命令:
$ d "s?\r$?\n?" <<< /path/
$ d "s?\r$?\n?" <<< /path/
Or you can echo the shell into stdout:
或者,您可以将shell回显到stdout中:
$ cat /path/ | d "s?\r$?\n?"
$ cat /path/ | d "s?\r$?\n?"
All that’s to this command is the command: substitute [?:delimiter] [\r$: regex] [?] [\n: replacement] [?] . The delimiter can be any character following the s. Good characters to u are characters that don’t usually appear in file names or files. Some examples are:
该命令的全部内容是命令: s ubstitute [?:delimiter] [\r$: regex] [?] [\n: replacement] [?] 。 分隔符可以是s之后的任何字符。 好的字符是通常不会出现在⽂件名或⽂件中的字符。 ⼀些例⼦是:
!
!
@
@
#
#
$
$笔记本连打印机
|
|
_颐和园万寿山
_
‘ ‘ (yes, even spaces)
''(是,甚⾄空格)
咸宜观
Pick your weapons wily.
明智地挑选武器。
更新多个CSV⽂件 (Update Multiple CSV Files)
小孩子手指头脱皮是怎么回事
To solve the issue of the multiple CSV files that need updating, we can get a bit fancier so that we can format things correctly. To update multiple files, they can just be appended onto the command as a space-parated list.
为了解决需要更新的多个CSV⽂件的问题,我们可能会提出⼀些建议,以便我们可以正确设置格式。 要更新多个⽂件,可以将它们作为空格分隔的列表附加到命令中。
$ date=`$(date -R)` d "s|[0-9]{4}/[0-9]{2}/[0-9]{2}|${date}|g" file1.csv file2.csv ...
文天祥从容就义
$ date=`$(date -R)` d "s|[0-9]{4}/[0-9]{2}/[0-9]{2}|${date}|g" file1.csv file2.csv ...
First, we t the date variable to output the date and time in RFC 5322 format. Then we run the d command substituting all strings matching “0000/00/00” and replace them with the date variable that we t prior. Finally, we run this on all the files inrted space-parated after the script definition.
⾸先,我们设置date变量以RFC 5322格式输出⽇期和时间。 然后,我们运⾏d命令,替换所有匹配“ 0000/00/00”的字符串,并将它们替换为我们先前设置的date变量。 最后,我们对在脚本定义后以空格分隔的所有⽂件运⾏此命令。
It’s that easy!
就这么简单!大拇指简笔画
资源资源 (Resources)
Photo by on
在 上 照⽚
What are you waiting for? Get out there! Start scripting some cool projects and expanding your knowledge. Sed is yet another tool in your toolbelt after today, and that’s something to be proud of.
你在等什么? ⾛出去! 开始编写⼀些很棒的项⽬的脚本,并扩展您的知识。 如今, Sed是⼯具带中的⼜⼀个⼯具,值得骄傲。
I hope you enjoyed the read. I’ve ud d from time to time before, but it’s a tool I continue to come back to since it’s available on so many *nix systems. Perhaps you’ll what you’ve learned here in an upcoming project or two. Hope you have fun regardless!
希望您喜欢阅读。 我以前不时使⽤d ,但由于它在许多* nix系统上可⽤,因此我会继续使⽤它。 也许您将在接下来的⼀两个项⽬中学到什么。 希望您玩得开⼼!
All the best and stay safe — Spencer
⼀切顺利并保持安全— Spencer
⼀维数据如何找出它的拐点
学会放弃>腐竹用热水泡还是冷水泡