mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-02-06 23:50:16 +08:00
Merge remote-tracking branch 'LCTT/master'
This commit is contained in:
commit
b59fc6f7a4
130
published/20191204 Java vs. Python- Which should you choose.md
Normal file
130
published/20191204 Java vs. Python- Which should you choose.md
Normal file
@ -0,0 +1,130 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-11679-1.html)
|
||||
[#]: subject: (Java vs. Python: Which should you choose?)
|
||||
[#]: via: (https://opensource.com/article/19/12/java-vs-python)
|
||||
[#]: author: (Archit Modi https://opensource.com/users/architmodi)
|
||||
|
||||
Java 与 Python:你应该选择哪个?
|
||||
======
|
||||
|
||||
> 比较世界上最流行的两种编程语言,并在投票中让我们知道你喜欢哪一个。
|
||||
|
||||
![](https://img.linux.net.cn/data/attachment/album/201912/16/095025dppnl2lgtykgggkt.jpg)
|
||||
|
||||
让我们比较一下世界上两种最受欢迎、最强大的编程语言:Java 和 Python!这两种语言有巨大的社区支持和库来执行几乎任何编程任务,尽管选择编程语言通常取决于开发人员的场景。在比较和对比之后,请投票分享你的观点。
|
||||
|
||||
### 是什么?
|
||||
|
||||
* **Java** 是一门通用面向对象的编程语言,主要用于开发从移动端到 Web 到企业级应用的各种应用。
|
||||
* **Python** 是一门高级面向对象的编程语言,主要用于 Web 开发、人工智能、机器学习、自动化和其他数据科学应用。
|
||||
|
||||
### 创建者
|
||||
|
||||
* **Java** 是由 James Gosling(Sun Microsystems)创造的。
|
||||
* **Python** 是由 Guido van Rossum 创造的。
|
||||
|
||||
### 开源状态
|
||||
|
||||
* **Java** 是免费的,(大部分)开源,但商业用途除外。
|
||||
* **Python** 对于所有场景都是免费、开源的。
|
||||
|
||||
### 平台依赖
|
||||
|
||||
* **Java** 根据它的 WORA (“<ruby>一次编写,到处运行<rt>write once, run anywhere</rt></ruby>”)哲学,它是平台无关的。
|
||||
* **Python** 依赖于平台。
|
||||
|
||||
### 编译或解释
|
||||
|
||||
* **Java** 是一门编译语言。Java 程序在编译时转换为字节码,而不是运行时。
|
||||
* **Python** 是一门解释性语言。Python 程序在运行时进行解释。
|
||||
|
||||
### 文件创建
|
||||
|
||||
* **Java**:编译后生成 `<filename>.class` 文件。
|
||||
* **Python**:在运行期,创建 `<filename>.pyc` 文件。
|
||||
|
||||
### 错误类型
|
||||
|
||||
* **Java** 有 2 种错误类型:编译和运行时错误。
|
||||
* **Python** 有 1 种错误类型:回溯(或运行时)错误。
|
||||
|
||||
### 静态或动态类型
|
||||
|
||||
* **Java** 是静态类型。当初始化变量时,需要在程序中指定变量的类型,因为类型检查是在编译时完成的。
|
||||
* **Python** 是动态类型。变量不需要在初始化时指定类型,因为类型检查是在运行时完成的。
|
||||
|
||||
### 语法
|
||||
|
||||
* **Java**:每个语句都需要以分号(`;` )结尾,并且代码块由大括号( `{}` )分隔。
|
||||
* **Python**:代码块通过缩进分隔(用户可以选择要使用的空格数,但在整个块中应保持一致)。
|
||||
|
||||
### 类的数量
|
||||
|
||||
* **Java**:在 Java 中的单个文件中只能存在一个公有顶级类。
|
||||
* **Python**:Python 中的单个文件中可以存在任意数量的类。
|
||||
|
||||
### 代码多少?
|
||||
|
||||
* **Java** 通常比 Python 要写更多代码行。
|
||||
* **Python**通常比 Java 要写更少代码行。
|
||||
|
||||
### 多重继承
|
||||
|
||||
* **Java** 不支持多重继承(从两个或多个基类继承)。
|
||||
* **Python** 支持多重继承,但由于继承复杂性、层次结构、依赖等各种问题,它很少实现。
|
||||
|
||||
### 多线程
|
||||
|
||||
* **Java** 多线程可以支持同时运行的两个或多个并发线程。
|
||||
* **Python** 使用全局解释器锁 (GIL),一次只允许运行单个线程(一个 CPU 核)。
|
||||
|
||||
### 执行速度
|
||||
|
||||
* **Java** 的执行时间通常比 Python 快。
|
||||
* **Python** 的执行时间通常比 Java 慢。
|
||||
|
||||
### Hello world
|
||||
|
||||
Java 的:
|
||||
|
||||
```
|
||||
public class Hello {
|
||||
public static void main([String][3][] args) {
|
||||
[System][4].out.println("Hello Opensource.com from Java!");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Python 的:
|
||||
|
||||
```
|
||||
print("Hello Opensource.com from Java!")
|
||||
```
|
||||
|
||||
### 运行程序
|
||||
|
||||
![Java vs. Python][5]
|
||||
|
||||
要运行 java 程序 `Hello.java`,你需要先编译它,这将创建一个 `Hello.class` 文件。只需运行类名 `java Hello`。对于 Python,只需运行文件 `python3 helloworld.py`。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/12/java-vs-python
|
||||
|
||||
作者:[Archit Modi][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/architmodi
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/code_development_programming.png?itok=M_QDcgz5 (Developing code.)
|
||||
[2]: tmp.Bpi8QYfp8j#poll
|
||||
[3]: http://www.google.com/search?hl=en&q=allinurl%3Adocs.oracle.com+javase+docs+api+string
|
||||
[4]: http://www.google.com/search?hl=en&q=allinurl%3Adocs.oracle.com+javase+docs+api+system
|
||||
[5]: https://opensource.com/sites/default/files/uploads/python-java-hello-world_0.png (Java vs. Python)
|
@ -1,105 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Zorin OS Responds to the Privacy Concerns)
|
||||
[#]: via: (https://itsfoss.com/zorin-os-privacy-concerns/)
|
||||
[#]: author: (Ankush Das https://itsfoss.com/author/ankush/)
|
||||
|
||||
Zorin OS Responds to the Privacy Concerns
|
||||
======
|
||||
|
||||
_**There were some privacy concerns around ‘data collection’ in Zorin OS. It’s FOSS spoke to Zorin OS CEO and here is his response to the controversy.**_
|
||||
|
||||
After a few days of [Zorin OS 15 Lite][1] release, a Reddit thread surfaced which flagged a privacy concern regarding the Linux distribution.
|
||||
|
||||
The [Reddit thread][2] focuses on the [privacy policy][3] of Zorin OS and warns users that Zorin OS is sending anonymous pings every 60 minutes without users’ consent, which is potentially a privacy issue.
|
||||
|
||||
![][4]
|
||||
|
||||
The policy in question can be quoted here as:
|
||||
|
||||
> _**Anonymous pings**: When using Zorin OS, your computer may occasionally send us a ping which includes an anonymous unique identifier for your computer. We use this information to count the number of active users of Zorin OS. The unique identifier does not identify you unless you (or someone acting on your behalf) discloses it separately. You may choose to disable these pings by uninstalling the “Zorin-os-census” package from your computer_
|
||||
|
||||
Now, there’s a lot of [discussions][5] surrounding the concern. There’s also a [YouTube video][6] talking about it.
|
||||
|
||||
In a nutshell, it’s a mess. Some insist that they collect our IP addresses and some users complain that they should ask about it while installing Zorin OS.
|
||||
|
||||
While I agree that they could add an opt-out option in the installation process – so I reached out to **Artyom Zorin** (_CEO, Zorin Group_) to clarify the situation.
|
||||
|
||||
### Zorin’s Clarification On What They Collect With Every Anonymous Ping
|
||||
|
||||
When I asked for an elaborate explanation of what the “**anonymous unique identifier**” includes, Artyom mentioned – “_It appears that there are some inaccuracies and misconceptions about the census in the comments sections_“.
|
||||
|
||||
To continue the explanation about the unique identifier, he assured that **their servers do not log IP addresses** when a ping arrives.
|
||||
|
||||
The zorin-os-census script **simply counts the number of unique computers using Zorin OS** and no personal data is being collected along with it.
|
||||
|
||||
Artyom explained in detail:
|
||||
|
||||
> The anonymous identifier is a series of letters and numbers which is randomly generated (not based on any external data) and only used for the Zorin OS Census. Its single purpose is to make sure that the computer isn’t double-counted when a ping is sent from a computer to the server. On a fully-installed Zorin OS system, the anonymous identifier can be found in /var/lib/zorin-os-census/uuid and should look like this:_68f2d95b-f51f-4a5d-9b48-a99c28691b89_
|
||||
> *
|
||||
> *We would like to clarify that no personal or personally-identifiable data is being collected by us and the server does not log IP addresses when pings arrive. The zorin-os-census script is only used to count the number of computers and users running Zorin OS after installation. Even I wouldn’t be able to tell which computer is my own from looking at the server-side database. I have attached a screenshot of a snippet of the database table displaying the information we store.
|
||||
|
||||
He also stressed his ‘commitment on privacy’:
|
||||
|
||||
> Privacy is an essential human right. It’s a core tenet of our mission to give you back control of your technology, and not the other way around. We make privacy a priority with every decision we make, and we’re committed to protecting it in every level of the software we build.
|
||||
|
||||
As you can observe in the response above, he shared a screenshot of how their database of unique identifiers looks like:
|
||||
|
||||
![][7]
|
||||
|
||||
If you’re still curious, you can also check out the [source code][8] for the zorin-os-census script.
|
||||
|
||||
### Can We Opt-Out Of It?
|
||||
|
||||
While the data collected may be ‘harmless’, it is important to give the option to the user whether or not they want Zorin OS to collect the data, right?
|
||||
|
||||
So, when I inquired about the same, he mentioned that i**t was already something planned for Zorin OS 15 Lite release**.
|
||||
|
||||
However, they did not want to rush to add it before properly testing it. Hence, they decided to keep it for the upcoming release (**Zorin OS 15.1**) which is planned to arrive in **early-to-mid December this year.**
|
||||
|
||||
> We have in fact been working on implementing an opt-out option for this into the Zorin OS installer (Ubiquity). To ensure the stability and accessibility of this new functionality we’re adding to Ubiquity, we have scheduled a period of time to translate the text strings and rigorously test the software (in order to avoid regressions), as the installer is a critical component of the operating system. Unfortunately, the testing period for the opt-out option didn’t complete before our planned release of Zorin OS 15 Lite, and we, therefore, decided not to risk adding it before we could guarantee its stability. However, we are on track to include the opt-out option in the upcoming Zorin OS 15.1 release, which we plan to release in early-to-mid December.
|
||||
|
||||
### Will It Be Something Similar To What Ubuntu Does?
|
||||
|
||||
Ubuntu does let you opt-out from collecting information about your computer.
|
||||
|
||||
So, when I asked if Zorin OS will add something similar to that, he responded with some details about how Ubuntu collects data and how Zorin OS is different from that.
|
||||
|
||||
He mentioned the fact that Ubuntu comes pre-installed with a **popularity-contest** package that **occasionally sends data of what packages the user has installed** to the Ubuntu Developers.
|
||||
|
||||
And, further clarified that **Zorin OS does not include that**.
|
||||
|
||||
> While Ubuntu’s telemetry tool gives users the option to not send extensive information about the computers to the Ubuntu developers, selecting the “No” option still sends a ping to Ubuntu’s servers .
|
||||
>
|
||||
> From our research, it is not clear whether Ubuntu’s servers store logs of users’ IP addresses when they receive telemetry data. In addition, Zorin OS does not include the “popularity-contest” package that is pre-installed in Ubuntu. This package is designed to occasionally send a list of all packages a user has installed on their computer to the Ubuntu developers.
|
||||
|
||||
**In the end…**
|
||||
|
||||
While the concern regarding the anonymous pings may not seem to a privacy threat, an opt-out option should be presented to the user while installing Zorin OS. Let’s wait and watch if it should arrive in the upcoming Zorin OS 15.1 release.
|
||||
|
||||
What do you think about the privacy concern mentioned above? Let us know your thoughts in the comments down below.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/zorin-os-privacy-concerns/
|
||||
|
||||
作者:[Ankush Das][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://itsfoss.com/author/ankush/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://itsfoss.com/zorin-os-lite/
|
||||
[2]: https://www.reddit.com/r/FreeAsInFreedom/comments/e0yhw4/beware_zorin_os_sends_anonymous_pings_every_60/
|
||||
[3]: https://zorinos.com/legal/privacy/
|
||||
[4]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2019/11/zorin-os-privacy-reddit.jpg?ssl=1
|
||||
[5]: https://www.reddit.com/r/linux/comments/e0zd5n/beware_zorin_os_sends_anonymous_pings_every_60/
|
||||
[6]: https://www.youtube.com/watch?v=bcgk9LvC36Y&feature=youtu.be&t=860
|
||||
[7]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2019/11/zorin-census-database.png?ssl=1
|
||||
[8]: https://launchpad.net/~zorinos/+archive/ubuntu/stable/+sourcepub/10183568/+listing-archive-extra
|
@ -1,89 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Open Source Music Notations Software MuseScore 3.3 Released!)
|
||||
[#]: via: (https://itsfoss.com/musescore/)
|
||||
[#]: author: (Ankush Das https://itsfoss.com/author/ankush/)
|
||||
|
||||
Open Source Music Notations Software MuseScore 3.3 Released!
|
||||
======
|
||||
|
||||
_**Brief: MuseScore is an open-source software to help you create, play, and print sheet music. They released a major update recently. So, we take a look at what MuseScore has to offer**_ _**overall.**_
|
||||
|
||||
### MuseScore: A Music Composition and Notation Software
|
||||
|
||||
![][1]
|
||||
|
||||
[MuseScore][2] is open-source software that lets you create, play, and print [sheet music][3].
|
||||
|
||||
You can even use a MIDI keyboard as input and simply play the tune you want to create the notation of.
|
||||
|
||||
In order to make use of it, you need to know how sheet music notations work. In either case, you can just play something using your MIDI keyboard or any other instrument and learn how the music notations work while using it.
|
||||
|
||||
So, it should come in handy for beginners and experts as well.
|
||||
|
||||
You can download and use MuseScore for free. However, if you want to share your music/composition and reach out to a wider community on the MuseScore platform, you can opt to create a free or premium account on [MuseScore.com][4].
|
||||
|
||||
### Features of MuseScore
|
||||
|
||||
![Musescore 3 Screenshot][5]
|
||||
|
||||
MuseScore includes a lot of things that can be highlighted. If you are someone who is not involved in making music notations for your compositions – you might have to dig deeper just like me.
|
||||
|
||||
Usually, I just head over to any [DAW available on Linux][6] and start playing something to record/loop it without needing to create the music notations. So, for me, MuseScore definitely presents a learning curve with all the features offered.
|
||||
|
||||
I’ll just list out the features with some brief descriptions – so you can explore them if it sounds interesting to you.
|
||||
|
||||
* Supports Input via MIDI keyboard
|
||||
* You can transfer to/from other programs via [MusicXML][7], MIDI, and other options.
|
||||
* A Huge collection of palettes (music symbols) to choose from.
|
||||
* You also get the ability to re-arrange the palettes and create your own list of most-used palettes or edit them.
|
||||
* Some plugins supported to extend the functionality
|
||||
* Import PDFs to read and play notations
|
||||
* Several instruments supported
|
||||
* Basic or Advanced layout of palettes to get started
|
||||
|
||||
|
||||
|
||||
Some of the recent key changes include the palettes redesign, accessibility, and the not input workflow. For reference, you can check out how the new palettes work:
|
||||
|
||||
### Installing MuseScore 3.3.3 on Ubuntu/Linux
|
||||
|
||||
The latest version of MuseScore is 3.3.3 with all the bug fixes and improvements to its recent [MuseScore 3.3 release][8].
|
||||
|
||||
You may find an older release in your Software Center (or your official repo). So, you can either opt for a Flatpak package, Snap, or maybe an AppImage from its [download page][9] with links for different Linux distributions.
|
||||
|
||||
[Download MuseScore][9]
|
||||
|
||||
**Wrapping Up**
|
||||
|
||||
I was quite fascinated to learn about MuseScore being an open-source and free solution to create, play, and print sheet music.
|
||||
|
||||
It may not be the most easy-to-use software there is – but when considering the work with music notations, it will help you learn more about it and help you with your work as well.
|
||||
|
||||
What do you think about MuseScore? Do share your thoughts in the comments below.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/musescore/
|
||||
|
||||
作者:[Ankush Das][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://itsfoss.com/author/ankush/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2019/11/musescore-3.jpg?ssl=1
|
||||
[2]: https://musescore.org/en
|
||||
[3]: https://en.wikipedia.org/wiki/Sheet_music
|
||||
[4]: https://musescore.com/
|
||||
[5]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2019/11/musescore-3-screenshot.jpg?ssl=1
|
||||
[6]: https://itsfoss.com/best-audio-editors-linux/
|
||||
[7]: https://en.wikipedia.org/wiki/MusicXML
|
||||
[8]: https://musescore.org/en/3.3
|
||||
[9]: https://musescore.org/en/download
|
@ -1,254 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Awk one-liners and scripts to help you sort text files)
|
||||
[#]: via: (https://opensource.com/article/19/11/how-sort-awk)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
Awk one-liners and scripts to help you sort text files
|
||||
======
|
||||
Awk is a powerful tool for doing tasks that might otherwise be left to
|
||||
other common utilities, including sort.
|
||||
![Green graph of measurements][1]
|
||||
|
||||
Awk is the ubiquitous Unix command for scanning and processing text containing predictable patterns. However, because it features functions, it's also justifiably called a programming language.
|
||||
|
||||
Confusingly, there is more than one awk. (Or, if you believe there can be only one, then there are several clones.) There's **awk**, the original program written by Aho, Weinberger, and Kernighan, and then there's **nawk**, **mawk**, and the GNU version, **gawk**. The GNU version of awk is a highly portable, free software version of the utility with several unique features, so this article is about GNU awk.
|
||||
|
||||
While its official name is gawk, on GNU+Linux systems it's aliased to awk and serves as the default version of that command. On other systems that don't ship with GNU awk, you must install it and refer to it as gawk, rather than awk. This article uses the terms awk and gawk interchangeably.
|
||||
|
||||
Being both a command and a programming language makes awk a powerful tool for tasks that might otherwise be left to **sort**, **cut**, **uniq**, and other common utilities. Luckily, there's lots of room in open source for redundancy, so if you're faced with the question of whether or not to use awk, the answer is probably a solid "maybe."
|
||||
|
||||
The beauty of awk's flexibility is that if you've already committed to using awk for a task, then you can probably stay in awk no matter what comes up along the way. This includes the eternal need to sort data in a way other than the order it was delivered to you.
|
||||
|
||||
### Sample set
|
||||
|
||||
Before exploring awk's sorting methods, generate a sample dataset to use. Keep it simple so that you don't get distracted by edge cases and unintended complexity. This is the sample set this article uses:
|
||||
|
||||
|
||||
```
|
||||
Aptenodytes;forsteri;Miller,JF;1778;Emperor
|
||||
Pygoscelis;papua;Wagler;1832;Gentoo
|
||||
Eudyptula;minor;Bonaparte;1867;Little Blue
|
||||
Spheniscus;demersus;Brisson;1760;African
|
||||
Megadyptes;antipodes;Milne-Edwards;1880;Yellow-eyed
|
||||
Eudyptes;chrysocome;Viellot;1816;Sothern Rockhopper
|
||||
Torvaldis;linux;Ewing,L;1996;Tux
|
||||
```
|
||||
|
||||
It's a small dataset, but it offers a good variety of data types:
|
||||
|
||||
* A genus and species name, which are associated with one another but considered separate
|
||||
* A surname, sometimes with first initials after a comma
|
||||
* An integer representing a date
|
||||
* An arbitrary term
|
||||
* All fields separated by semi-colons
|
||||
|
||||
|
||||
|
||||
Depending on your educational background, you may consider this a 2D array or a table or just a line-delimited collection of data. How you think of it is up to you, because awk doesn't expect anything more than text. It's up to you to tell awk how you want to parse it.
|
||||
|
||||
### The sort cheat
|
||||
|
||||
If you just want to sort a text dataset by a specific, definable field (think of a "cell" in a spreadsheet), then you can use the [sort command][2].
|
||||
|
||||
### Fields and records
|
||||
|
||||
Regardless of the format of your input, you must find patterns in it so that you can focus on the parts of the data that are important to you. In this example, the data is delimited by two factors: lines and fields. Each new line represents a new _record_, as you would likely see in a spreadsheet or database dump. Within each line, there are distinct _fields_ (think of them as cells in a spreadsheet) that are separated by semicolons (;).
|
||||
|
||||
Awk processes one record at a time, so while you're structuring the instructions you will give to awk, you can focus on just one line. Establish what you want to do with one line, then test it (either mentally or with awk) on the next line and a few more. You'll end up with a good hypothesis on what your awk script must do in order to provide you with the data structure you want.
|
||||
|
||||
In this case, it's easy to see that each field is separated by a semicolon. For simplicity's sake, assume you want to sort the list by the very first field of each line.
|
||||
|
||||
Before you can sort, you must be able to focus awk on just the first field of each line, so that's the first step. The syntax of an awk command in a terminal is **awk**, followed by relevant options, followed by your awk command, and ending with the file of data you want to process.
|
||||
|
||||
|
||||
```
|
||||
$ awk --field-separator=";" '{print $1;}' penguins.list
|
||||
Aptenodytes
|
||||
Pygoscelis
|
||||
Eudyptula
|
||||
Spheniscus
|
||||
Megadyptes
|
||||
Eudyptes
|
||||
Torvaldis
|
||||
```
|
||||
|
||||
Because the field separator is a character that has special meaning to the Bash shell, you must enclose the semicolon in quotes or precede it with a backslash. This command is useful only to prove that you can focus on a specific field. You can try the same command using the number of another field to view the contents of another "column" of your data:
|
||||
|
||||
|
||||
```
|
||||
$ awk --field-separator=";" '{print $3;}' penguins.list
|
||||
Miller,JF
|
||||
Wagler
|
||||
Bonaparte
|
||||
Brisson
|
||||
Milne-Edwards
|
||||
Viellot
|
||||
Ewing,L
|
||||
```
|
||||
|
||||
Nothing has been sorted yet, but this is good groundwork.
|
||||
|
||||
### Scripting
|
||||
|
||||
Awk is more than just a command; it's a programming language with indices and arrays and functions. That's significant because it means you can grab a list of fields you want to sort by, store the list in memory, process it, and then print the resulting data. For a complex series of actions such as this, it's easier to work in a text file, so create a new file called **sort.awk** and enter this text:
|
||||
|
||||
|
||||
```
|
||||
#!/bin/gawk -f
|
||||
|
||||
BEGIN {
|
||||
FS=";";
|
||||
}
|
||||
```
|
||||
|
||||
This establishes the file as an awk script that executes the lines contained in the file.
|
||||
|
||||
The **BEGIN** statement is a special setup function provided by awk for tasks that need to occur only once. Defining the built-in variable **FS**, which stands for _field separator_ and is the same value you set in your awk command with **\--field-separator**, only needs to happen once, so it's included in the **BEGIN** statement.
|
||||
|
||||
#### Arrays in awk
|
||||
|
||||
You already know how to gather the values of a specific field by using the **$** notation along with the field number, but in this case, you need to store it in an array rather than print it to the terminal. This is done with an awk array. The important thing about an awk array is that it contains keys and values. Imagine an array about this article; it would look something like this: **author:"seth",title:"How to sort with awk",length:1200**. Elements like **author** and **title** and **length** are keys, with the following contents being values.
|
||||
|
||||
The advantage to this in the context of sorting is that you can assign any field as the key and any record as the value, and then use the built-in awk function **asorti()** (sort by index) to sort by the key. For now, assume arbitrarily that you _only_ want to sort by the second field.
|
||||
|
||||
Awk statements _not_ preceded by the special keywords **BEGIN** or **END** are loops that happen at each record. This is the part of the script that scans the data for patterns and processes it accordingly. Each time awk turns its attention to a record, statements in **{}** (unless preceded by **BEGIN** or **END**) are executed.
|
||||
|
||||
To add a key and value to an array, create a variable (in this example script, I call it **ARRAY**, which isn't terribly original, but very clear) containing an array, and then assign it a key in brackets and a value with an equals sign (**=**).
|
||||
|
||||
|
||||
```
|
||||
{ # dump each field into an array
|
||||
ARRAY[$2] = $R;
|
||||
}
|
||||
```
|
||||
|
||||
In this statement, the contents of the second field (**$2**) are used as the key term, and the current record (**$R**) is used as the value.
|
||||
|
||||
### The asorti() function
|
||||
|
||||
In addition to arrays, awk has several basic functions that you can use as quick and easy solutions for common tasks. One of the functions introduced in GNU awk, **asorti()**, provides the ability to sort an array by key (or _index_) or value.
|
||||
|
||||
You can only sort the array once it has been populated, meaning that this action must not occur with every new record but only the final stage of your script. For this purpose, awk provides the special **END** keyword. The inverse of **BEGIN**, an **END** statement happens only once and only after all records have been scanned.
|
||||
|
||||
Add this to your script:
|
||||
|
||||
|
||||
```
|
||||
END {
|
||||
asorti(ARRAY,SARRAY);
|
||||
# get length
|
||||
j = length(SARRAY);
|
||||
|
||||
for (i = 1; i <= j; i++) {
|
||||
printf("%s %s\n", SARRAY[i],ARRAY[SARRAY[i]])
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The **asorti()** function takes the contents of **ARRAY**, sorts it by index, and places the results in a new array called **SARRAY** (an arbitrary name I invented for this article, meaning _Sorted ARRAY_).
|
||||
|
||||
Next, the variable **j** (another arbitrary name) is assigned the results of the **length()** function, which counts the number of items in **SARRAY**.
|
||||
|
||||
Finally, use a **for** loop to iterate through each item in **SARRAY** using the **printf()** function to print each key, followed by the corresponding value of that key in **ARRAY**.
|
||||
|
||||
### Running the script
|
||||
|
||||
To run your awk script, make it executable:
|
||||
|
||||
|
||||
```
|
||||
`$ chmod +x sorter.awk`
|
||||
```
|
||||
|
||||
And then run it against the **penguin.list** sample data:
|
||||
|
||||
|
||||
```
|
||||
$ ./sorter.awk penguins.list
|
||||
antipodes Megadyptes;antipodes;Milne-Edwards;1880;Yellow-eyed
|
||||
chrysocome Eudyptes;chrysocome;Viellot;1816;Sothern Rockhopper
|
||||
demersus Spheniscus;demersus;Brisson;1760;African
|
||||
forsteri Aptenodytes;forsteri;Miller,JF;1778;Emperor
|
||||
linux Torvaldis;linux;Ewing,L;1996;Tux
|
||||
minor Eudyptula;minor;Bonaparte;1867;Little Blue
|
||||
papua Pygoscelis;papua;Wagler;1832;Gentoo
|
||||
```
|
||||
|
||||
As you can see, the data is sorted by the second field.
|
||||
|
||||
This is a little restrictive. It would be better to have the flexibility to choose at runtime which field you want to use as your sorting key so you could use this script on any dataset and get meaningful results.
|
||||
|
||||
### Adding command options
|
||||
|
||||
You can add a command variable to an awk script by using the literal value **var** in your script. Change your script so that your iterative clause uses **var** when creating your array:
|
||||
|
||||
|
||||
```
|
||||
{ # dump each field into an array
|
||||
ARRAY[$var] = $R;
|
||||
}
|
||||
```
|
||||
|
||||
Try running the script so that it sorts by the third field by using the **-v var** option when you execute it:
|
||||
|
||||
|
||||
```
|
||||
$ ./sorter.awk -v var=3 penguins.list
|
||||
Bonaparte Eudyptula;minor;Bonaparte;1867;Little Blue
|
||||
Brisson Spheniscus;demersus;Brisson;1760;African
|
||||
Ewing,L Torvaldis;linux;Ewing,L;1996;Tux
|
||||
Miller,JF Aptenodytes;forsteri;Miller,JF;1778;Emperor
|
||||
Milne-Edwards Megadyptes;antipodes;Milne-Edwards;1880;Yellow-eyed
|
||||
Viellot Eudyptes;chrysocome;Viellot;1816;Sothern Rockhopper
|
||||
Wagler Pygoscelis;papua;Wagler;1832;Gentoo
|
||||
```
|
||||
|
||||
### Fixes
|
||||
|
||||
This article has demonstrated how to sort data in pure GNU awk. The script can be improved so, if it's useful to you, spend some time researching [awk functions][3] on gawk's man page and customizing the script for better output.
|
||||
|
||||
Here is the complete script so far:
|
||||
|
||||
|
||||
```
|
||||
#!/usr/bin/awk -f
|
||||
# GPLv3 appears here
|
||||
# usage: ./sorter.awk -v var=NUM FILE
|
||||
|
||||
BEGIN { FS=";"; }
|
||||
|
||||
{ # dump each field into an array
|
||||
ARRAY[$var] = $R;
|
||||
}
|
||||
|
||||
END {
|
||||
asorti(ARRAY,SARRAY);
|
||||
# get length
|
||||
j = length(SARRAY);
|
||||
|
||||
for (i = 1; i <= j; i++) {
|
||||
printf("%s %s\n", SARRAY[i],ARRAY[SARRAY[i]])
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/11/how-sort-awk
|
||||
|
||||
作者:[Seth Kenlon][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/seth
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/metrics_lead-steps-measure.png?itok=DG7rFZPk (Green graph of measurements)
|
||||
[2]: https://opensource.com/article/19/10/get-sorted-sort
|
||||
[3]: https://www.gnu.org/software/gawk/manual/html_node/Built_002din.html#Built_002din
|
@ -1,63 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (algzjh)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (An idiot's guide to Kubernetes, low-code developers, and other industry trends)
|
||||
[#]: via: (https://opensource.com/article/19/12/technology-advice-and-other-industry-trends)
|
||||
[#]: author: (Tim Hildred https://opensource.com/users/thildred)
|
||||
|
||||
An idiot's guide to Kubernetes, low-code developers, and other industry trends
|
||||
======
|
||||
A weekly look at open source community, market, and industry trends.
|
||||
![Person standing in front of a giant computer screen with numbers, data][1]
|
||||
|
||||
As part of my role as a senior product marketing manager at an enterprise software company with an open source development model, I publish a regular update about open source community, market, and industry trends for product marketers, managers, and other influencers. Here are five of my and their favorite articles from that update.
|
||||
|
||||
## [An idiot's guide to Kubernetes][2]
|
||||
|
||||
> Kubernetes has already grown to encompass new features which have made it a better container platform for enterprise software. Elements like security and advanced networking have been pulled into the main body of the upstream Kubernetes code, and are now available for everyone to use.
|
||||
>
|
||||
> It is, however, true that there will always be supplementary needs to cover other aspects of an enterprise solution; things like logging and performance monitoring. This is where secondary packages like Istio come into play, bringing extra functionality, but keeping the Kubernetes core to a reasonable size and set of features.
|
||||
|
||||
**The impact**: I've always found that it is easy to take awareness of technology developments for granted. When everyone you interact with is also on the "cutting edge" your perspective gets skewed to the point where you might even think that someone who doesn't know about the latest in (INSERT PREFERRED TECHNOLOGY HERE) just isn't keeping up, when really it just hasn't started to impact their ability to do what they need to. Those people aren't idiots; they're our friends, customers, partners, collaborators, and communities.
|
||||
|
||||
## [Gartner: What to consider before adopting low-code development][3]
|
||||
|
||||
> Despite the focus on business IT teams, Gartner finds an increasingly important developer community is the central IT professional developers needing rapid development of simple applications, or to build minimum viable products or multi-experience capabilities. And when application leaders use low-code within conventional application projects, they might want to use a standard IT DevOps automation approach alongside low-code tooling.
|
||||
|
||||
**The impact**: A growing range of use cases and user experiences can be addressed and delivered through applications that require less time and skill to create. And low-code developers will also probably coalesce into a distinct group with their own norms and subculture.
|
||||
|
||||
## [Nokia argues cloud-native is essential to 5G core][4]
|
||||
|
||||
> Nokia outlined five key business objectives for 5G that can only be delivered by a cloud-native environment. Those include: better bandwidth, latency, and density; the extension of services via network slicing to new enterprises, industries, and [IoT][5] markets; rapid service deployments defined by agility and efficiency; new services that go beyond traditional broadband, voice, and messaging; and the advent of digital services that harness end-to-end networking to capture more revenue.
|
||||
|
||||
**The impact**: This is most meaningful in the context of the increasing number of things that will be hooked up to the network. 4G was primarily about more and more mobile phones; 5G is only really necessary when you start connecting everything else. Whereas 4G meant richer apps on our phones, 5G has very little to do with phones at all.
|
||||
|
||||
## [APIs: The hidden business accelerator][6]
|
||||
|
||||
> For organisations to have a successful digital transformation, an API strategy is critical. From unlocking valuable data to speeding up development time, APIs are the humble heroes of the digital era. Those already experimenting with APIs are already feeling the benefits. For example, research has shown that 53 percent of businesses that have used APIs cite them as increasing productivity, and 29 percent claim they experienced revenue growth as a direct result of API use. When treated as discoverable and reusable products that live beyond one project, APIs help lay a flexible foundation for continuous change.
|
||||
|
||||
**The impact**: The hidden business accelerator is actually the idea that capability should be packaged in a way that allows it to be repurposed and combined in contexts that its original provider didn't anticipate.
|
||||
|
||||
_I hope you enjoyed this list of what stood out to me from last week and come back next Monday for more open source community, market, and industry trends._
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/12/technology-advice-and-other-industry-trends
|
||||
|
||||
作者:[Tim Hildred][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/thildred
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/data_metrics_analytics_desktop_laptop.png?itok=9QXd7AUr (Person standing in front of a giant computer screen with numbers, data)
|
||||
[2]: https://www.cbronline.com/feature/an-idiots-guide-to-kubernetes
|
||||
[3]: https://www.computerweekly.com/feature/Gartner-What-to-consider-before-adopting-low-code-development
|
||||
[4]: https://www.sdxcentral.com/articles/news/nokia-argues-cloud-native-is-essential-to-5g-core/2019/11/
|
||||
[5]: https://www.sdxcentral.com/5g/iot/ (IoT)
|
||||
[6]: https://www.cbronline.com/opinion/digital-transformation-3
|
@ -1,12 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How to change colors and themes in Vim)
|
||||
[#]: via: (https://opensource.com/article/19/12/colors-themes-vim)
|
||||
[#]: author: (Rashan Smith https://opensource.com/users/rsmith)
|
||||
|
||||
How to change colors and themes in Vim
|
||||
======
|
||||
Style your command line Vim with your favorite color scheme.
|
@ -1,120 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Breaking Linux files into pieces with the split command)
|
||||
[#]: via: (https://www.networkworld.com/article/3489256/breaking-linux-files-into-pieces-with-the-split-command.html)
|
||||
[#]: author: (Sandra Henry-Stocker https://www.networkworld.com/author/Sandra-Henry_Stocker/)
|
||||
|
||||
Breaking Linux files into pieces with the split command
|
||||
======
|
||||
Some simple Linux commands allow you to break up files and reassemble them as needed in order to accommodate size restrictions on file size for storage or email attachments
|
||||
[Marco Verch][1] [(CC BY 2.0)][2]
|
||||
|
||||
Linux systems provide a very easy-to-use command for breaking files into pieces. This is something that you might need to do prior to uploading your files to some storage site that limits file sizes or emailing them as attachments. To split a file into pieces, you simply use the split command.
|
||||
|
||||
```
|
||||
$ split bigfile
|
||||
```
|
||||
|
||||
By default, the split command uses a very simple naming scheme. The file chunks will be named xaa, xab, xac, etc., and, presumably, if you break up a file that is sufficiently large, you might even get chunks named xza and xzz.
|
||||
|
||||
[[Get regularly scheduled insights by signing up for Network World newsletters.]][3]
|
||||
|
||||
Unless you ask, the command runs without giving you any feedback. You can, however, use the --verbose option if you would like to see the file chunks as they are being created.
|
||||
|
||||
[][4]
|
||||
|
||||
BrandPost Sponsored by HPE
|
||||
|
||||
[Take the Intelligent Route with Consumption-Based Storage][4]
|
||||
|
||||
Combine the agility and economics of HPE storage with HPE GreenLake and run your IT department with efficiency.
|
||||
|
||||
```
|
||||
$ split –-verbose bigfile
|
||||
creating file 'xaa'
|
||||
creating file 'xab'
|
||||
creating file 'xac'
|
||||
```
|
||||
|
||||
You can also contribute to the file naming by providing a prefix. For example, to name all the pieces of your original file bigfile.xaa, bigfile.xab and so on, you would add your prefix to the end of your split command like so:
|
||||
|
||||
```
|
||||
$ split –-verbose bigfile bigfile.
|
||||
creating file 'bigfile.aa'
|
||||
creating file 'bigfile.ab'
|
||||
creating file 'bigfile.ac'
|
||||
```
|
||||
|
||||
Note that a dot is added to the end of the prefix shown in the above command. Otherwise, the files would have names like bigfilexaa rather than bigfile.xaa.
|
||||
|
||||
Note that the split command does _not_ remove your original file, just creates the chunks. If you want to specify the size of the file chunks, you can add that to your command using the -b option. For example:
|
||||
|
||||
```
|
||||
$ split -b100M bigfile
|
||||
```
|
||||
|
||||
File sizes can be specified in kilobytes, megabytes, gigabytes … up to yottabytes! Just use the appropriate letter from K, M, G, T, P, E, Z and Y.
|
||||
|
||||
If you want your file to be split based on the number of lines in each chunk rather than the number of bytes, you can use the -l (lines) option. In this example, each file will have 1,000 lines except, of course, for the last one which may have fewer lines.
|
||||
|
||||
```
|
||||
$ split --verbose -l1000 logfile log.
|
||||
creating file 'log.aa'
|
||||
creating file 'log.ab'
|
||||
creating file 'log.ac'
|
||||
creating file 'log.ad'
|
||||
creating file 'log.ae'
|
||||
creating file 'log.af'
|
||||
creating file 'log.ag'
|
||||
creating file 'log.ah'
|
||||
creating file 'log.ai'
|
||||
creating file 'log.aj'
|
||||
```
|
||||
|
||||
If you need to reassemble your file from pieces on a remote site, you can do that fairly easily using a cat command like one of these:
|
||||
|
||||
```
|
||||
$ cat x?? > original.file
|
||||
$ cat log.?? > original.file
|
||||
```
|
||||
|
||||
Splitting and reassembling with the commands shown above should work for binary files as well as text files. In this example, we’ve split the zip binary into 50 kilobyte chunks, used cat to reassemble them and then compared the assembled and original files. The diff command verifies that the files are the same.
|
||||
|
||||
```
|
||||
$ split --verbose -b50K zip zip.
|
||||
creating file 'zip.aa'
|
||||
creating file 'zip.ab'
|
||||
creating file 'zip.ac'
|
||||
creating file 'zip.ad'
|
||||
creating file 'zip.ae'
|
||||
$ cat zip.a? > zip.new
|
||||
$ diff zip zip.new
|
||||
$ <== no output = no difference
|
||||
```
|
||||
|
||||
The only caution I have to give at this point is that, if you use split often and use the default naming, you will likely end up overwriting some chunks with others and maybe sometimes having more chunks than you were expecting because some were left over from some earlier split.
|
||||
|
||||
Join the Network World communities on [Facebook][5] and [LinkedIn][6] to comment on topics that are top of mind.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.networkworld.com/article/3489256/breaking-linux-files-into-pieces-with-the-split-command.html
|
||||
|
||||
作者:[Sandra Henry-Stocker][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.networkworld.com/author/Sandra-Henry_Stocker/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.flickr.com/photos/30478819@N08/34879296673/in/photolist-V9avJ2-LysA9-qVeu6t-dV4dkC-RWNeA5-LFKPG-aLpKTg-aLpJoK-4rN35a-97zDK4-7fevx8-mBSVT-64r2D4-8TbXFw-4g2Wgv-4pAdnq-4g6Ycf-9pt9t9-ceyN2u-LYckrJ-23sDdLH-dAQgiK-25eyt6N-UuAEk9-koNDTn-dAVK2j-ea8feG-bWpNKQ-bzJNPM-dAQ22K-dnkd1e-8qkaFp-dnCtBr-dnknKi-TKXaei-dnkjzV-RxvhHd-pQXTfa-c3crQf-dnkwXG-dnfW2K-2SKdMh-efHTUr-5mMzpp-XdMr5c-88H1s3-d67Gth-aMuG6v-Uio4v1-KZt3M
|
||||
[2]: https://creativecommons.org/licenses/by/2.0/legalcode
|
||||
[3]: https://www.networkworld.com/newsletters/signup.html
|
||||
[4]: https://www.networkworld.com/article/3440100/take-the-intelligent-route-with-consumption-based-storage.html?utm_source=IDG&utm_medium=promotions&utm_campaign=HPE20773&utm_content=sidebar ( Take the Intelligent Route with Consumption-Based Storage)
|
||||
[5]: https://www.facebook.com/NetworkWorld/
|
||||
[6]: https://www.linkedin.com/company/network-world
|
@ -1,32 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (7 ways to remember Linux commands)
|
||||
[#]: via: (https://www.linux.com/tutorials/7-ways-to-remember-linux-commands/)
|
||||
[#]: author: (Swapnil Bhartiya https://www.linux.com/author/swapnil/)
|
||||
|
||||
7 ways to remember Linux commands
|
||||
======
|
||||
|
||||
Some Linux commands are very easy to remember. The names may have only a couple letters and they often relate directly to what you want to do – like cd for changing directories or pwd for displaying the present working directory. Others can be very difficult to remember, especially if what you want to do relies on using a series of options.
|
||||
|
||||
So, let’s look at some commands and tricks that can help you remember commands that do just what you need them to do and that make issuing those commands so much easier.
|
||||
|
||||
[Source: [Network World][1]]
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.linux.com/tutorials/7-ways-to-remember-linux-commands/
|
||||
|
||||
作者:[Swapnil Bhartiya][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.linux.com/author/swapnil/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.networkworld.com/article/3489537/7-ways-to-remember-linux-commands.html
|
@ -1,5 +1,5 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
|
@ -0,0 +1,65 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Customize your Linux desktop with the Trinity Desktop Environment)
|
||||
[#]: via: (https://opensource.com/article/19/12/linux-trinity-desktop-environment-tde)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
Customize your Linux desktop with the Trinity Desktop Environment
|
||||
======
|
||||
This article is part of a special series of 24 days of Linux desktops.
|
||||
TDE is a fully customizable Linux desktop that will be instantly
|
||||
recognizable to anyone who knew and loved KDE 3.
|
||||
![Person standing in front of a giant computer screen with numbers, data][1]
|
||||
|
||||
When KDE 4 was released in 2008, KDE 3 went into support mode until support was dropped entirely. That's the usual lifecycle of software, desktops included, but the KDE 3 fanbase wasn't universally pleased with KDE 4, and some of them decided a fork was in order.
|
||||
|
||||
Some of them formed a new project with the mission of preserving the look and feel of KDE 3, starting from KDE 3.5.10 (the last official release in the 3.x series), and then forking Qt 3 into TQt to keep the underlying technology updated. Today, the [Trinity Desktop Environment][2] (TDE) delivers a traditional desktop environment that looks and feels essentially the same as KDE 3 did 10-plus years ago.
|
||||
|
||||
You may find the Trinity desktop included in the software repository of your distribution. Before you install it, be aware that it is meant to provide a full desktop experience, so many TDE apps are installed along with the desktop. If you're already running another desktop, you may find yourself with redundant applications (two PDF readers, two media players, two file managers, and so on).
|
||||
|
||||
If your software repo doesn't offer Trinity, or you just don't want to install it and all of its applications, you can install a TDE distribution in a virtual machine, such as [GNOME Boxes][3]. I used the [exeGNU][4] distribution for the screenshots below, and there are other distros listed on [TDE's LiveCDs][5] page.
|
||||
|
||||
### TDE desktop tour
|
||||
|
||||
The Trinity Desktop Environment is a very traditional desktop. It's one that's likely to be familiar to you—whether or not you've used KDE at all, in fact. It has one panel at the bottom of the screen that contains an application menu in the left corner, a taskbar in the middle, and a system tray in the right, and there are icons for common locations on the desktop. It behaves exactly as you'd expect a desktop to behave, and you can probably change whatever you want to change because TDE is completely customizable.
|
||||
|
||||
If you were a KDE 3 user in the past, revisiting the Trinity Desktop Environment is a little like stepping back in time. While a side-by-side comparison of the two desktops might reveal significant differences, it would be a real challenge to find a deviation in TDE from the desktop you remember. All the key components are there: the sidebar tabs, the Konqueror file manager, the traditional application menu, the retractable panel, and the classic layout.
|
||||
|
||||
![TDE on exeGNU][6]
|
||||
|
||||
How different this is from KDE 4 or KDE 5 is a matter of perspective. To many users, the TDE default is pretty much the same as the default layout of late KDE 4 or current KDE 5 desktops. As is often the case, however, the biggest differences are in the smallest of details. The absence of Dolphin in favor of [Konqueror][7] is one of the biggest non-changes. Konqueror has quite literally set the standard for both file management and web browsing (KHTML is the code that Apple and Google forked to create the Safari and Chrome browsers), so preserving it as the central desktop application is particularly noteworthy.
|
||||
|
||||
All the "old" applications are still there, and seemingly not a button or widget has moved from the old default 3.5 location. The defaults are always set to what they were in KDE 3.5, but nearly everything can be rearranged, changed, hidden, or disassembled. User experience is supreme, and TDE never assumes that any two users want the same experience.
|
||||
|
||||
![Trinity Control Center][8]
|
||||
|
||||
To a tried and true KDE 3.5.x user, using TDE is just a matter of surrendering to muscle memory.
|
||||
|
||||
### Trinity and open source
|
||||
|
||||
Trinity, along with the Mate fork of GNOME 2, is one of the most direct examples of how open source empowers developers to sustain a beloved software project that's otherwise reached its end. Not all software is kept alive by a fork and a dedicated team of true believers, but sometimes it does happen, and when it does, it results in greater variety and more choice. Whether you choose KDE 5 or TDE, or GNOME 3 or Mate, you get to make those choices because open source empowers developers and users to make technology work better for everyone.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/12/linux-trinity-desktop-environment-tde
|
||||
|
||||
作者:[Seth Kenlon][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/seth
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/data_metrics_analytics_desktop_laptop.png?itok=9QXd7AUr (Person standing in front of a giant computer screen with numbers, data)
|
||||
[2]: https://www.trinitydesktop.org/
|
||||
[3]: https://opensource.com/article/19/5/getting-started-gnome-boxes-virtualization
|
||||
[4]: http://exegnulinux.net
|
||||
[5]: https://wiki.trinitydesktop.org/LiveCDs
|
||||
[6]: https://opensource.com/sites/default/files/uploads/advent-trinity.jpg (TDE on exeGNU)
|
||||
[7]: https://kde.org/applications/internet/org.kde.konqueror
|
||||
[8]: https://opensource.com/sites/default/files/uploads/advent-trinity-control.jpg (Trinity Control Center)
|
@ -1,156 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Java vs. Python: Which should you choose?)
|
||||
[#]: via: (https://opensource.com/article/19/12/java-vs-python)
|
||||
[#]: author: (Archit Modi https://opensource.com/users/architmodi)
|
||||
|
||||
Java vs. Python:你应该选择哪个?
|
||||
======
|
||||
比较世界上最流行的两种编程语言,并在投票中让我们知道你喜欢哪一个。
|
||||
![Developing code.][1]
|
||||
|
||||
让我们比较一下世界上两种最受欢迎、最强大的编程语言:Java 和 Python!这两种语言有巨大的社区支持和库来执行几乎任何编程任务,尽管选择编程语言通常取决于开发人员的场景。在比较和对比之后,请投票[分享你的观点][2]。
|
||||
|
||||
### 是什么?
|
||||
|
||||
* **Java** 是一门通用面向对象的编程语言,主要用于开发从移动端到 Web 到企业级应用的各种应用。
|
||||
* **Python** 是一门高级面向对象的编程语言,主要用于 Web 开发、人工智能、机器学习、自动化和其他数据科学应用。
|
||||
|
||||
|
||||
|
||||
### 创建者
|
||||
|
||||
* **Java** 是由 James Gosling(Sun Microsystems)创造的。
|
||||
* **Python** 是由 Guido van Rossum 创造的。
|
||||
|
||||
|
||||
|
||||
### 开源状态
|
||||
|
||||
* **Java** 是免费的,(大部分)开源,但商业用途除外。
|
||||
* **Python** 所有场景均免费。
|
||||
|
||||
|
||||
|
||||
### 平台依赖
|
||||
|
||||
* **Java** 根据它的 WORA (”一次编写,到处运行“)哲学,它是平台无关的。
|
||||
* **Python** 依赖于平台。
|
||||
|
||||
|
||||
|
||||
### 编译或解释
|
||||
|
||||
* **Java** 是一门编译语言。Java 程序在编译时转换为字节码,而不是运行时。
|
||||
* **Python** 是一门解释性语言。Python 程序在运行时进行解释。
|
||||
|
||||
|
||||
|
||||
### 文件创建
|
||||
|
||||
* **Java**:编译后生成 **<filename>.class** 文件。
|
||||
* **Python**:在运行期,创建 **<filename>.pyc** 文件
|
||||
|
||||
|
||||
|
||||
### 错误类型
|
||||
|
||||
* **Java** 有 2 种错误类型:编译和运行时错误。
|
||||
* **Python** 有 1 种错误类型:回溯(或运行时)错误。
|
||||
|
||||
|
||||
|
||||
### 静态或动态类型
|
||||
|
||||
* **Java** 是静态类型。当初始化变量时,需要在程序中指定变量的类型,因为类型检查是在编译时完成的。
|
||||
* **Python** 是动态类型。变量不需要在初始化时指定类型,因为类型检查是在运行时完成的。
|
||||
|
||||
|
||||
|
||||
### 语法
|
||||
|
||||
* **Java**:每个语句都需要以分号 (\*; ) 结尾,并且代码块由大括号 ( {} ) 分隔。
|
||||
* **Python**:代码块通过缩进分隔(用户可以选择要使用的空格数,但在整个块中应保持一致)。
|
||||
|
||||
|
||||
|
||||
### 类的数量
|
||||
|
||||
* **Java**:在 Java 中的单个文件中只能存在一个公有顶级类。
|
||||
* **Python**:Python 中的单个文件中可以存在任意数量的类。
|
||||
|
||||
|
||||
|
||||
### 代码更多或更少?
|
||||
|
||||
* **Java** 通常比 Python 要写更多代码行。
|
||||
* **Python**通常比 Java 要写更少代码行。
|
||||
|
||||
|
||||
|
||||
### 多重继承
|
||||
|
||||
* **Java** 不支持多重继承(从两个或多个基类继承)。
|
||||
* **Python** 支持多重继承,但由于继承复杂性、层次结构、依赖等各种问题,它很少实现。
|
||||
|
||||
|
||||
|
||||
### 多线程
|
||||
|
||||
* **Java** 多线程可以支持同时运行的两个或多个并发线程。
|
||||
* **Python** 使用全局解释器锁 (GIL),一次只允许运行单个线程 ( CPU 核)。
|
||||
|
||||
|
||||
|
||||
### 执行速度
|
||||
|
||||
* **Java** 的执行时间通常比 Python 快。
|
||||
* **Python** 的执行时间通常比 Java 慢。
|
||||
|
||||
|
||||
|
||||
### Java 的 Hello world
|
||||
|
||||
|
||||
```
|
||||
public class Hello {
|
||||
public static void main([String][3][] args) {
|
||||
[System][4].out.println("Hello Opensource.com from Java!");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Python 的 Hello world
|
||||
|
||||
|
||||
```
|
||||
`print("Hello Opensource.com from Java!")`
|
||||
```
|
||||
|
||||
### 运行程序
|
||||
|
||||
![Java vs. Python][5]
|
||||
|
||||
要运行 java 程序 ”Hello.java“,你需要先编译它,这将创建一个 ”Hello.class“ 文件。只需运行类名 ”java Hello“。对于 Python,只需运行文件 ”python3 helloworld.py“。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/12/java-vs-python
|
||||
|
||||
作者:[Archit Modi][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/architmodi
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/code_development_programming.png?itok=M_QDcgz5 (Developing code.)
|
||||
[2]: tmp.Bpi8QYfp8j#poll
|
||||
[3]: http://www.google.com/search?hl=en&q=allinurl%3Adocs.oracle.com+javase+docs+api+string
|
||||
[4]: http://www.google.com/search?hl=en&q=allinurl%3Adocs.oracle.com+javase+docs+api+system
|
||||
[5]: https://opensource.com/sites/default/files/uploads/python-java-hello-world_0.png (Java vs. Python)
|
@ -0,0 +1,246 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (wxy)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Awk one-liners and scripts to help you sort text files)
|
||||
[#]: via: (https://opensource.com/article/19/11/how-sort-awk)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
单行 Awk 或脚本帮助你排序文本文件
|
||||
======
|
||||
|
||||
> Awk 是一个强大的工具,可以执行某些可能由其它常见实用程序(包括 `sort`)来完成的任务。
|
||||
|
||||
![Green graph of measurements][1]
|
||||
|
||||
Awk 是个普遍存在的 Unix 命令,用于扫描和处理包含可预测模式的文本。但是,由于它具有函数功能,因此也可以合理地称为编程语言。
|
||||
|
||||
令人困惑的是,有不止一个 awk。(或者,如果你认为只有一个,那么其它几个就是克隆。)有 `awk`(由Aho、Weinberger 和 Kernighan 编写的原始程序),然后有 `nawk` 、`mawk` 和 GNU 版本 `gawk`。GNU 版本的 awk 是该实用程序的一个高度可移植的自由软件版本,具有几个独特的功能,因此本文是关于 GNU awk 的。
|
||||
|
||||
虽然它的正式名称是 `gawk`,但在 GNU+Linux 系统上,它的别名是 `awk`,并用作该命令的默认版本。 在其他没有带有 GNU awk 的系统上,你必须安装它并将其称为 `gawk`,而不是 `awk`。本文互换使用术语 `awk` 和 `gawk`。
|
||||
|
||||
`awk` 既是命令语言又是编程语言,它使其成为一个强大的工具,可以处理原本留给 `sort`、`cut`、`uniq` 和其他常见实用程序的任务。幸运的是,开放源代码中有很多冗余空间,因此,如果你面临是否使用`awk` 的问题,答案可能是肯定的“也许”。
|
||||
|
||||
`awk` 的灵活之美在于,如果你已经承诺使用 `awk` 来完成一项任务,那么无论接下来发生什么,你都可以继续使用 `awk`。这包括对数据排序而不是按交付给你的顺序的永恒需求。
|
||||
|
||||
### 样本数据集
|
||||
|
||||
在探索 `awk` 的排序方法之前,请生成要使用的样本数据集。保持简单,这样你就不会为极端情况和意想不到的复杂性所困扰。这是本文使用的样本集:
|
||||
|
||||
```
|
||||
Aptenodytes;forsteri;Miller,JF;1778;Emperor
|
||||
Pygoscelis;papua;Wagler;1832;Gentoo
|
||||
Eudyptula;minor;Bonaparte;1867;Little Blue
|
||||
Spheniscus;demersus;Brisson;1760;African
|
||||
Megadyptes;antipodes;Milne-Edwards;1880;Yellow-eyed
|
||||
Eudyptes;chrysocome;Viellot;1816;Sothern Rockhopper
|
||||
Torvaldis;linux;Ewing,L;1996;Tux
|
||||
```
|
||||
|
||||
这是一个很小的数据集,但它提供了多种数据类型:
|
||||
|
||||
* 属名和种名,彼此相关但又是分开的
|
||||
* 姓,有时以逗号开头的首字母缩写
|
||||
* 代表日期的整数
|
||||
* 任意术语
|
||||
* 所有字段均以分号分隔
|
||||
|
||||
根据你的教育背景,你可能会认为这是二维数组或表格,或者只是行分隔的数据集合。你如何看待它取决于你,因为 `awk` 只认识文本。由你决定告诉 `awk` 你想如何解析它。
|
||||
|
||||
### 只想排序
|
||||
|
||||
如果你只想按特定的可定义字段(例如电子表格中的“单元格”)对文本数据集进行排序,则可以使用 [sort 命令][2]。
|
||||
|
||||
### 字段和记录
|
||||
|
||||
字段和记录
|
||||
|
||||
无论输入的格式如何,都必须在其中找到模式才可以专注于对你重要的数据部分。在此示例中,数据由两个因素定界:行和字段。每行都代表一个新的*记录*,就如你在电子表格或数据库转储中看到的一样。在每一行中,都有用分号(`;`)分隔的不同的*字段*(将其视为电子表格中的单元格)。
|
||||
|
||||
`awk` 一次只处理一条记录,因此,当你在组织发给 `awk` 的这指令时,你可以只关注一行记录。写下你想对一行数据执行的操作,然后在下一行进行测试(无论是心理上还是用 `awk` 进行测试),然后再进行其他一些测试。最后,你要对你的 `awk` 脚本要处理的数据做好假设,以便可以按你要的数据结构提供给你数据。
|
||||
|
||||
在这个例子中,很容易看到每个字段都用分号隔开。为简单起见,假设你要按每行的第一字段对列表进行排序。
|
||||
|
||||
在进行排序之前,你必须能够让 `awk` 只关注在每行的第一个字段上,因此这是第一步。终端中 awk 命令的语法为 `awk',后跟相关选项,后跟你的 `awk` 命令,最后是要处理的数据文件。
|
||||
|
||||
```
|
||||
$ awk --field-separator=";" '{print $1;}' penguins.list
|
||||
Aptenodytes
|
||||
Pygoscelis
|
||||
Eudyptula
|
||||
Spheniscus
|
||||
Megadyptes
|
||||
Eudyptes
|
||||
Torvaldis
|
||||
```
|
||||
|
||||
因为字段分隔符是对 Bash shell 具有特殊含义的字符,所以必须将分号括在引号中或在其前面加上反斜杠。此命令仅用于证明你可以专注于特定字段。你可以使用另一个字段的编号尝试相同的命令,以查看数据的另一个“列”的内容:
|
||||
|
||||
```
|
||||
$ awk --field-separator=";" '{print $3;}' penguins.list
|
||||
Miller,JF
|
||||
Wagler
|
||||
Bonaparte
|
||||
Brisson
|
||||
Milne-Edwards
|
||||
Viellot
|
||||
Ewing,L
|
||||
```
|
||||
|
||||
我们尚未进行任何排序,但这是良好的基础。
|
||||
|
||||
### 脚本编程
|
||||
|
||||
`awk` 不仅仅是命令,它是一种具有索引、数组和函数的编程语言。这很重要,因为这意味着你可以获取要排序的字段列表,将列表存储在内存中,进行处理,然后打印结果数据。对于诸如此类的一系列复杂操作,在文本文件中进行操作会更容易,因此请创建一个名为 `sort.awk` 的新文件并输入以下文本:
|
||||
|
||||
|
||||
```
|
||||
#!/bin/gawk -f
|
||||
|
||||
BEGIN {
|
||||
FS=";";
|
||||
}
|
||||
```
|
||||
|
||||
这会将文件建立为 `awk` 脚本,该脚本中包含执行的行。
|
||||
|
||||
`BEGIN` 语句是 `awk` 提供的特殊设置功能,用于只需要执行一次的任务。定义内置变量 `FS`,它代表<ruby>字段分隔符<rt>field separator</rt></ruby>,并且与你在 `awk` 命令中使用 `--field-separator` 设置的值相同,它只需执行一次,因此它包含在 `BEGIN` 语句中。
|
||||
|
||||
#### awk 中的数组
|
||||
|
||||
你已经知道如何通过使用 `$` 符号和字段编号来收集特定字段的值,但是在这种情况下,你需要将其存储在数组中而不是将其打印到终端。这是通过 `awk` 数组完成的。`awk` 数组的重要之处在于它包含键和值。 想象一下有关本文的内容;它看起来像这样:`author:"seth",title:"How to sort with awk",length:1200`。诸如作者、标题和长度之类的元素是键,跟着的内容为值。
|
||||
|
||||
在排序的上下文中这样做的好处是,你可以将任何字段分配为键,将任何记录分配为值,然后使用内置的 `awk` 函数 `asorti()`(按索引排序)按键进行排序。现在,随便假设你*只*想按第二个字段排序。
|
||||
|
||||
*没有*被特殊关键字 `BEGIN` 或 `END` 引起来的 `awk` 语句是在每个记录都有执行的循环。这是脚本的一部分,该脚本扫描数据中的模式并进行相应的处理。每次 `awk` 将注意力转移到一条记录上时,都会执行 `{}` 中的语句(除非以 `BEGIN` 或 `END` 开头)。
|
||||
|
||||
要将键和值添加到数组,请创建一个包含数组的变量(在本示例脚本中,我将其称为 `ARRAY `,虽然不是很原汁原味,但很清楚),然后在方括号中分配给它键和用等号(`=`)连接的值。
|
||||
|
||||
```
|
||||
{ # dump each field into an array
|
||||
ARRAY[$2] = $R;
|
||||
}
|
||||
```
|
||||
|
||||
在此语句中,第二个字段的内容(`$2`)用作关键字,而当前记录(`$R`)用作值。
|
||||
|
||||
|
||||
### asorti() 函数
|
||||
|
||||
除了数组之外,`awk` 还具有一些基本函数,你可以将它们用作常见任务的快速简便的解决方案。GNU awk中引入的函数之一 `asorti()` 提供了按键(*索引*)或值对数组进行排序的功能。
|
||||
|
||||
你只能在对数组进行填充后对其进行排序,这意味着此操作不能对每个新记录都触发,而只能在脚本的最后阶段进行。为此,`awk` 提供了特殊的 `END` 关键字。与 `BEGIN` 相反,`END` 语句仅在扫描了所有记录之后才触发一次。
|
||||
|
||||
将这些添加到你的脚本:
|
||||
|
||||
```
|
||||
END {
|
||||
asorti(ARRAY,SARRAY);
|
||||
# get length
|
||||
j = length(SARRAY);
|
||||
|
||||
for (i = 1; i <= j; i++) {
|
||||
printf("%s %s\n", SARRAY[i],ARRAY[SARRAY[i]])
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
`asorti()` 函数获取 `ARRAY` 的内容,按索引对其进行排序,然后将结果放入名为 `SARRAY` 的新数组(我在本文中发明的任意名称,表示“排序的 ARRAY”)。
|
||||
|
||||
接下来,将变量 `j`(另一个任意名称)分配给 `length()` 函数的结果,该函数计算 `SARRAY` 中的项数。
|
||||
|
||||
最后,使用 `for` 循环使用 `printf()` 函数遍历 `SARRAY` 中的每一项,以打印每个键,然后在 `ARRAY` 中打印该键的相应值。
|
||||
|
||||
### 运行该脚本
|
||||
|
||||
要运行你的 `awk` 脚本,先使其可执行:
|
||||
|
||||
```
|
||||
$ chmod +x sorter.awk
|
||||
```
|
||||
|
||||
然后针对 `penguin.list` 示例数据运行它:
|
||||
|
||||
```
|
||||
$ ./sorter.awk penguins.list
|
||||
antipodes Megadyptes;antipodes;Milne-Edwards;1880;Yellow-eyed
|
||||
chrysocome Eudyptes;chrysocome;Viellot;1816;Sothern Rockhopper
|
||||
demersus Spheniscus;demersus;Brisson;1760;African
|
||||
forsteri Aptenodytes;forsteri;Miller,JF;1778;Emperor
|
||||
linux Torvaldis;linux;Ewing,L;1996;Tux
|
||||
minor Eudyptula;minor;Bonaparte;1867;Little Blue
|
||||
papua Pygoscelis;papua;Wagler;1832;Gentoo
|
||||
```
|
||||
|
||||
如你所见,数据按第二个字段排序。
|
||||
|
||||
这有点限制性。最好可以在运行时灵活选择要用作排序键的字段,以便可以在任何数据集上使用此脚本并获得有意义的结果。
|
||||
|
||||
### 添加命令选项
|
||||
|
||||
你可以通过在脚本中使用文字值 `var` 将命令变量添加到 `awk` 脚本中。更改脚本,以使迭代子句在创建数组时使用 `var`:
|
||||
|
||||
```
|
||||
{ # dump each field into an array
|
||||
ARRAY[$var] = $R;
|
||||
}
|
||||
```
|
||||
|
||||
尝试运行脚本,以便在执行脚本时使用 `-v var` 选项将其按第三字段排序:
|
||||
|
||||
```
|
||||
$ ./sorter.awk -v var=3 penguins.list
|
||||
Bonaparte Eudyptula;minor;Bonaparte;1867;Little Blue
|
||||
Brisson Spheniscus;demersus;Brisson;1760;African
|
||||
Ewing,L Torvaldis;linux;Ewing,L;1996;Tux
|
||||
Miller,JF Aptenodytes;forsteri;Miller,JF;1778;Emperor
|
||||
Milne-Edwards Megadyptes;antipodes;Milne-Edwards;1880;Yellow-eyed
|
||||
Viellot Eudyptes;chrysocome;Viellot;1816;Sothern Rockhopper
|
||||
Wagler Pygoscelis;papua;Wagler;1832;Gentoo
|
||||
```
|
||||
|
||||
### 修正
|
||||
|
||||
本文演示了如何在纯 GNU awk 中对数据进行排序。你可以对脚本进行改进,以便对你有用,花一些时间在`gawk` 的手册页上研究 [awk 函数][3]并自定义脚本以获得更好的输出。
|
||||
|
||||
这是到目前为止的完整脚本:
|
||||
|
||||
```
|
||||
#!/usr/bin/awk -f
|
||||
# GPLv3 appears here
|
||||
# usage: ./sorter.awk -v var=NUM FILE
|
||||
|
||||
BEGIN { FS=";"; }
|
||||
|
||||
{ # dump each field into an array
|
||||
ARRAY[$var] = $R;
|
||||
}
|
||||
|
||||
END {
|
||||
asorti(ARRAY,SARRAY);
|
||||
# get length
|
||||
j = length(SARRAY);
|
||||
|
||||
for (i = 1; i <= j; i++) {
|
||||
printf("%s %s\n", SARRAY[i],ARRAY[SARRAY[i]])
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/11/how-sort-awk
|
||||
|
||||
作者:[Seth Kenlon][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[wxy](https://github.com/wxy)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/seth
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/metrics_lead-steps-measure.png?itok=DG7rFZPk (Green graph of measurements)
|
||||
[2]: https://opensource.com/article/19/10/get-sorted-sort
|
||||
[3]: https://www.gnu.org/software/gawk/manual/html_node/Built_002din.html#Built_002din
|
@ -7,21 +7,21 @@
|
||||
[#]: via: (https://opensource.com/article/19/11/python-web-api-flask)
|
||||
[#]: author: (Rachel Waston https://opensource.com/users/rachelwaston)
|
||||
|
||||
How to write a Python web API with Flask
|
||||
如何使用Flask编写Python Web API
|
||||
======
|
||||
Use Flask, one of the fastest-growing Python frameworks, to fetch data
|
||||
from a server, in this quick tutorial.
|
||||
|
||||
这是一个快速教程,用来展示如何通过Flask(目前发展最迅速的Python框架之一)来从服务器获取数据。
|
||||
![spiderweb diagram][1]
|
||||
|
||||
[Python][2] is a high-level, object-oriented programming language known for its simple syntax. It is consistently among the top-rated programming languages for building RESTful APIs.
|
||||
[Python][2]是一个以语法简洁著称的高级的,面向对象的程序语言。它一直都是一个用来构建RESTful API的顶级编程语言。
|
||||
|
||||
[Flask][3] is a customizable Python framework that gives developers complete control over how users access data. Flask is a "micro-framework" based on Werkzeug's [WSGI][4] toolkit and Jinja 2's templating engine. It is designed as a web framework for RESTful API development.
|
||||
[Flask][3]是一个高度可定制化的Python框架,可以为开发人员提供用户访问数据方式的完全控制。Flask是一个基于Werkzeug的[WSGI][4]工具包和Jinja 2模板引擎的”微框架“。它是一个被设计来开发RESTful API的web框架。
|
||||
|
||||
Flask is one of the fastest-growing Python frameworks, and popular websites, including Netflix, Pinterest, and LinkedIn, have incorporated Flask into their development stacks. Here's an example of how Flask can permit users to fetch data from a server using the HTTP GET method.
|
||||
Flask是Python发展最迅速的框架之一,很多知名网站如:Netflix, Pinterest, 和LinkedIn都将Flask纳入了它们的开发技术栈。下面是一个简单的示例,展示了Flask是如何允许用户通过HTTP GET请求来从服务器获取数据的。
|
||||
|
||||
### Set up a Flask application
|
||||
### 初始化一个Flask应用
|
||||
|
||||
First, create a structure for your Flask application. You can do this at any location on your system.
|
||||
首先,创建一个你的Flask项目的目录结构。你可以在你系统的任何地方来做这件事。
|
||||
|
||||
|
||||
```
|
||||
@ -37,10 +37,12 @@ Collecting Flask>=0.8 (from flask-restful)
|
||||
[...]
|
||||
```
|
||||
|
||||
### Import the Flask modules
|
||||
### 导入Flask模块
|
||||
|
||||
Next, import the **flask** module and its **flask_restful** library into your **main.py** code:
|
||||
|
||||
然后,在你的**main.py**代码中导入**flask**模块和它的**flask_restful**库:
|
||||
|
||||
|
||||
```
|
||||
from flask import Flask
|
||||
@ -67,10 +69,12 @@ if __name__ == '__main__':
|
||||
app.run(debug=True)
|
||||
```
|
||||
|
||||
### Run the app
|
||||
### 运行app
|
||||
|
||||
Flask includes a built-in HTTP server for testing. Test the simple API you built:
|
||||
|
||||
Flask包含一个内建的用于测试的HTTP服务器。来测试一下这个你创建的简单的API:
|
||||
|
||||
|
||||
```
|
||||
(env) $ python main.py
|
||||
@ -82,7 +86,7 @@ Flask includes a built-in HTTP server for testing. Test the simple API you bui
|
||||
* Running on <http://127.0.0.1:5000/> (Press CTRL+C to quit)
|
||||
```
|
||||
|
||||
Starting the development server starts your Flask application, which contains a method named **get** to respond to a simple HTTP GET request. You can test it using **wget** or **curl** or any web browser. The URL to use is provided in Flask's output after you start the server.
|
||||
启动开发服务器时将启动Flask应用程序,该应用程序包含一个名为 **get** 的方法来响应简单的HTTP GET请求。你可以通过 **wget**、**curl** 命令或者任意的web浏览器来测试它。
|
||||
|
||||
|
||||
```
|
||||
@ -102,29 +106,26 @@ $ curl <http://localhost:5000>
|
||||
}
|
||||
```
|
||||
|
||||
To see a more complex version of a similar web API using Python and Flask, navigate to the Library of Congress' [Chronicling America][5] website, which provides access to information about historic newspapers and digitized newspaper pages.
|
||||
要查看使用Python和Flask的类似Web API的更复杂版本,请导航至美国国会图书馆的[Chronicling America] [5]网站,该网站可提供有关这些信息的历史报纸和数字化报纸。
|
||||
|
||||
### Why use Flask?
|
||||
### 为什么使用 Flask?
|
||||
|
||||
Flask has several major benefits:
|
||||
Flask有以下几个主要的优点:
|
||||
|
||||
1. Python is popular and widely used, so anyone who knows Python can develop for Flask.
|
||||
2. It's lightweight and minimalistic.
|
||||
3. Built with security in mind.
|
||||
4. Great documentation with plenty of clear, working example code.
|
||||
1. Python很流行并且广泛被应用,所以任何熟悉Python的人都可以使用Flask来开发。
|
||||
2. 它轻巧而简约。
|
||||
3. 考虑安全性而构建。
|
||||
4. 出色的文档,其中包含大量清晰,有效的示例代码。
|
||||
|
||||
还有一些潜在的缺点:
|
||||
|
||||
1. 它轻巧而简约。但如果您正在寻找具有大量捆绑库和预制组件的框架,那么这可能不是最佳选择。
|
||||
2. 如果必须围绕Flask构建自己的框架,则你可能会发现维护自定义项的成本可能会抵消使用Flask的好处。
|
||||
|
||||
|
||||
如果您要构建Web程序或API,可以考虑选择Flask。它功能强大且健壮,并且其优秀的项目文档使入门变得容易。试用一下,评估一下,看看它是否适合您的项目。
|
||||
|
||||
There are also some potential drawbacks:
|
||||
|
||||
1. It's lightweight and minimalistic. If you're looking for a framework with lots of bundled libraries and prefabricated components, this may not be your best option.
|
||||
2. If you have to build your own framework around Flask, you might find that the cost of maintaining your customization negates the benefit of using Flask.
|
||||
|
||||
|
||||
|
||||
If you're looking to build a web app or API, Flask is a good option to consider. It's powerful and robust, and the project documentation makes it easy to get started. Try it out, evaluate it, and see if it's right for your project.
|
||||
|
||||
Learn more in this lesson in Python exception handling and how to do it in a secure manner.
|
||||
在本课中了解更多信息关于Python异常处理以及如何以安全的方式进行操作。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
@ -132,7 +133,7 @@ via: https://opensource.com/article/19/11/python-web-api-flask
|
||||
|
||||
作者:[Rachel Waston][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
译者:[hj24](https://github.com/hj24)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
@ -0,0 +1,63 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (algzjh)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (An idiot's guide to Kubernetes, low-code developers, and other industry trends)
|
||||
[#]: via: (https://opensource.com/article/19/12/technology-advice-and-other-industry-trends)
|
||||
[#]: author: (Tim Hildred https://opensource.com/users/thildred)
|
||||
|
||||
面向 Kubernetes,低代码开发人员和其他行业趋势的傻瓜指南
|
||||
======
|
||||
每周查看开源社区,市场和行业趋势。
|
||||
![Person standing in front of a giant computer screen with numbers, data][1]
|
||||
|
||||
我在一家采用开源开发模型的企业软件公司担任高级产品营销经理,作为该职位的一部分,我定期为产品营销人员,经理和其他有影响力的人发布有关开源社区,市场和行业趋势的最新信息。这里有该更新中我和他们最喜欢的四篇文章。
|
||||
|
||||
## [Kubernetes 的傻瓜指南][2]
|
||||
|
||||
> Kubernetes 已经发展出了新的特性,这使其成为企业软件的更好的容器平台。安全性和高级网络等元素已被纳入 Kubernetes 上游代码的主体,并且现在可供所有人使用。
|
||||
>
|
||||
> 然而,企业解决方案的其他方面总会有补充需求;比如日志记录和性能监控。这就是像 Istio 等辅助包发挥作用的地方,它带来了额外的功能,但是仍使 Kubernetes 的核心保持了合理的大小和特性集。
|
||||
|
||||
**影响**: 我总是发现,人们很容易把对技术发展的认识视为理所当然。当与你打交道的每个人都处于“最前沿”时,你的观点就会歪曲到这样的程度:你甚至可能会认为对最新的(此处插入首选技术)一无所知的人跟不上潮流,而实际上这并没有开始影响他们做自己需要做的事情的能力。那些人不是白痴;他们是我们的朋友、客户、合作伙伴、合作者和社区。
|
||||
|
||||
## [Gartner: 采用低代码开发之前应该考虑什么][3]
|
||||
|
||||
> 尽管专注于业务 IT 团队,但 Gartner(高德纳咨询公司) 发现,一个日益重要的开发人员社区是需要快速开发简单应用程序或构建最低可行产品或多体验功能的核心 IT 专业开发人员。当应用程序领导者在传统的应用程序项目中使用低代码时,他们可能希望使用标准的 IT DevOps 自动化方法和低代码工具。
|
||||
|
||||
**影响**: 越来越多的用例和用户体验可以通过需要更少时间和技能来创建的应用程序来处理和交互。而低代码开发人员也可能会结合成一个具有他们自己的规范和亚文化的独特群体。
|
||||
|
||||
## [诺基亚认为云原生对 5G 核心至关重要][4]
|
||||
|
||||
> 诺基亚概述了 5G 的五个关键业务目标,这些目标只能通过云原生环境来实现。其中包括:更好的带宽、延迟和密度;通过网络切片将服务扩展到新的企业、行业和[物联网][5]市场;根据敏捷性和效率定义的快速服务部署;超越传统带宽、语音和信息传递的新服务;以及利用端到端网络获取更多收入的数字服务的出现。
|
||||
|
||||
**影响**: 在越来越多的事物连接到网络的情况下,这是最有意义的。4G 主要与越来越多的手机有关;只有当你开始连接其他所有东西时,5G 才是真正必要的。4G 意味着我们的手机上有更丰富的应用程序,而 5G 几乎与手机无关。
|
||||
|
||||
## [APIs: 隐藏的业务加速器][6]
|
||||
|
||||
> 要想让组织成功地进行数字化转型,API 策略至关重要。从解锁有价值的数据到加快开发时间,API 都是数字时代谦逊的英雄。那些已经尝试过 API 的人已经感受到了好处。例如,研究表明,使用 API 的企业中,有 53% 认为它们提高了生产力,而 29% 声称它们的收入增长是使用 API 的直接结果。当 API 被视为存在于一个项目之外的可发现和可重用的产品时,它有助于为持续的变更奠定灵活的基础。
|
||||
|
||||
**影响**: 隐藏的业务加速器实际上是这样一种思想,即功能应该以一种方式进行打包,使其能够在原始提供者没有预料到的环境中进行重新利用和组合。
|
||||
|
||||
_我希望你喜欢这份上周给我留下深刻印象的列表,并于下周一回来了解更多开源社区、市场和行业的趋势。_
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/12/technology-advice-and-other-industry-trends
|
||||
|
||||
作者:[Tim Hildred][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[algzjh](https://github.com/algzjh)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/thildred
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/data_metrics_analytics_desktop_laptop.png?itok=9QXd7AUr "Person standing in front of a giant computer screen with numbers, data"
|
||||
[2]: https://www.cbronline.com/feature/an-idiots-guide-to-kubernetes
|
||||
[3]: https://www.computerweekly.com/feature/Gartner-What-to-consider-before-adopting-low-code-development
|
||||
[4]: https://www.sdxcentral.com/articles/news/nokia-argues-cloud-native-is-essential-to-5g-core/2019/11/
|
||||
[5]: https://www.sdxcentral.com/5g/iot/ "IoT"
|
||||
[6]: https://www.cbronline.com/opinion/digital-transformation-3
|
@ -0,0 +1,109 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Breaking Linux files into pieces with the split command)
|
||||
[#]: via: (https://www.networkworld.com/article/3489256/breaking-linux-files-into-pieces-with-the-split-command.html)
|
||||
[#]: author: (Sandra Henry-Stocker https://www.networkworld.com/author/Sandra-Henry_Stocker/)
|
||||
|
||||
使用 split 命令分割 Linux 文件
|
||||
======
|
||||
一些简单的 Linux 命令能让你根据需要分割以及重新组合文件,来适应存储或电子邮件附件大小的限制
|
||||
[Marco Verch][1] [(CC BY 2.0)][2]
|
||||
|
||||
Linux 系统提供了一个非常易于使用的命令来分割文件。在将文件上传到限制大小的存储网站或者作为邮件附件之前,你可能需要执行此操作。要将文件分割为多个文件块,只需使用 split 命令。
|
||||
|
||||
```
|
||||
$ split bigfile
|
||||
```
|
||||
|
||||
默认情况下,split 命令使用非常简单的命名方案。文件块将被命名为 xaa、xab、xac等,并且,大概地,如果你将足够大的文件分割,你甚至可能会得到名为 xza 和 xzz 的块。
|
||||
|
||||
|
||||
除非你要求,否则该命令将无任何反馈地运行。但是,如果你想在创建文件块时看到它们,可以使用 --verbose 选项。
|
||||
|
||||
```
|
||||
$ split –-verbose bigfile
|
||||
creating file 'xaa'
|
||||
creating file 'xab'
|
||||
creating file 'xac'
|
||||
```
|
||||
|
||||
你还可以给文件命名前缀。例如,要将原始文件命名为 bigfile.xaa、bigfile.xab等,你可以将前缀添加到 split 命令的末尾,如下所示:
|
||||
|
||||
```
|
||||
$ split –-verbose bigfile bigfile.
|
||||
creating file 'bigfile.aa'
|
||||
creating file 'bigfile.ab'
|
||||
creating file 'bigfile.ac'
|
||||
```
|
||||
|
||||
请注意,上述命令中显示的前缀的末尾会添加一个点。否则,文件将是 bigfilexaa 之类的名称,而不是 bigfile.xaa。
|
||||
|
||||
请注意,split 命令_不会_删除你的原始文件,只是创建了文件块。如果要指定文件块的大小,可以使用 -b 选项将其添加到命令中。例如:
|
||||
|
||||
```
|
||||
$ split -b100M bigfile
|
||||
```
|
||||
|
||||
文件大小可以是 KB、MB,GB,最大可以是 YB!只需使 K、M、G、T、P、E、Z 和 Y 这些合适的字母。
|
||||
|
||||
如果要基于每个块中的行数而不是字节数来拆分文件,那么可以使用 -l(行)选项。在此示例中,每个文件将有 1000 行,当然,最后一个文件可能有较少的行。
|
||||
|
||||
```
|
||||
$ split --verbose -l1000 logfile log.
|
||||
creating file 'log.aa'
|
||||
creating file 'log.ab'
|
||||
creating file 'log.ac'
|
||||
creating file 'log.ad'
|
||||
creating file 'log.ae'
|
||||
creating file 'log.af'
|
||||
creating file 'log.ag'
|
||||
creating file 'log.ah'
|
||||
creating file 'log.ai'
|
||||
creating file 'log.aj'
|
||||
```
|
||||
|
||||
如果你需要在远程站点上重新组合文件,那么可以使用如下所示的 cat 命令轻松地完成此操作:
|
||||
|
||||
```
|
||||
$ cat x?? > original.file
|
||||
$ cat log.?? > original.file
|
||||
```
|
||||
|
||||
上面所示的分割和组合命令适合于二进制和文本文件。在此示例中,我们将 zip 二进制文件分割为 50KB 的块,之后使用 cat 重新组合了它们,然后比较了组合后的文件和原始文件。diff 命令验证文件是否相同。
|
||||
|
||||
```
|
||||
$ split --verbose -b50K zip zip.
|
||||
creating file 'zip.aa'
|
||||
creating file 'zip.ab'
|
||||
creating file 'zip.ac'
|
||||
creating file 'zip.ad'
|
||||
creating file 'zip.ae'
|
||||
$ cat zip.a? > zip.new
|
||||
$ diff zip zip.new
|
||||
$ <== 无输出 = 无差别
|
||||
```
|
||||
|
||||
我唯一要提醒的一点的是,如果你经常使用 split 并使用默认命名,那么某些文件块可能会覆盖其他的文件块,甚至会比你预期的更多,因为有些是更早之前分割的。
|
||||
|
||||
加入 [Facebook][5] 和 [LinkedIn][6] 上的 Network World 社区,评论热门主题。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.networkworld.com/article/3489256/breaking-linux-files-into-pieces-with-the-split-command.html
|
||||
|
||||
作者:[Sandra Henry-Stocker][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.networkworld.com/author/Sandra-Henry_Stocker/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.flickr.com/photos/30478819@N08/34879296673/in/photolist-V9avJ2-LysA9-qVeu6t-dV4dkC-RWNeA5-LFKPG-aLpKTg-aLpJoK-4rN35a-97zDK4-7fevx8-mBSVT-64r2D4-8TbXFw-4g2Wgv-4pAdnq-4g6Ycf-9pt9t9-ceyN2u-LYckrJ-23sDdLH-dAQgiK-25eyt6N-UuAEk9-koNDTn-dAVK2j-ea8feG-bWpNKQ-bzJNPM-dAQ22K-dnkd1e-8qkaFp-dnCtBr-dnknKi-TKXaei-dnkjzV-RxvhHd-pQXTfa-c3crQf-dnkwXG-dnfW2K-2SKdMh-efHTUr-5mMzpp-XdMr5c-88H1s3-d67Gth-aMuG6v-Uio4v1-KZt3M
|
||||
[2]: https://creativecommons.org/licenses/by/2.0/legalcode
|
||||
[5]: https://www.facebook.com/NetworkWorld/
|
||||
[6]: https://www.linkedin.com/company/network-world
|
Loading…
Reference in New Issue
Block a user