一些命令行小技巧：wc、sort、sed 和 tr
命令行
![](/data/attachment/album/202108/10/085720hyd795y1wrmd5rx9.jpg)


Linux 发行版十分好用，而且它们有一些用户可能不知道的技巧。让我们来看看一些命令行实用工具，当你热衷于终端而不是 GUI 时，它们可能更顺手。


我们都知道在一个系统上使用终端会更高效。当你编辑和排版一个文本文件时，终端会让你确切的感受到，生活如此简单。


本文将向你介绍 `wc`、`sort`、`tr` 和 `sed` 命令。


### wc


`wc` 是一个实用工具，全称是 “word count”。顾名思义，它可以用来统计任何文件的行数、单词数和字节数。


让我们来看看它是如何工作的：



```
$ wc filename
lines words characters filename

```

输出的是文件的行数、单词数、字符数和文件名。


想获得特定的输出，我们必须使用选项：


* `-c` 打印字节总数
* `-l` 打印行数
* `-w` 打印单词总数
* `-m` 打印字符总数


#### wc 示例


让我们来看看它的运行结果。


让我们从一个文本文件 `lormipsm.txt` 开始。首先，我们通过 `cat` 查看文件内容，然后使用 `wc`：



```
$ cat loremipsm.txt
Linux is the best-known and most-used open source operating system.
As an operating system, Linux is software that sits underneath all of the other software on a computer,
receiving requests from those programs and replaying these requests to the computer's hardware.

$ wc loremipsm.txt
3 41 268 loremipsm.txt

```

假设我只想查看文件的字节数：



```
$ wc -c loremipsm.txt
268 loremipsm.txt

```

查看文件的行数：



```
$ wc -l loremipsm.txt
3 loremipsm.txt

```

查看文件的单词数：



```
$ wc -w loremipsm.txt
41 loremipsm.txt

```

现在只查看文件的字符数：



```
$ wc -m loremipsm.txt
268 loremipsm.txt

```

### sort


`sort` 命令是最有用的工具之一。它会对文件的数据进行排序。可以根据字符或数字进行升序或降序排列。它也可以用来对文件中的行进行排序和随机化。


使用 `sort` 非常简单。我们需要做的仅仅是提供一个文件名：



```
$ sort filename

```

默认的是按照字母顺序对数据进行排序。需要注意的是 `sort` 命令仅仅是对数据进行排序展示。它并不会改写文件。


使用 `sort` 命令的一些有用的选项：


* `-r` 将文件中的行按倒序进行排序
* `-R` 将文件中的行打乱为随机顺序
* `-o` 将输出保存到另一个文件中
* `-k` 按照特定列进行排序
* `-t` 使用指定的分隔符，而不使用空格
* `-n` 根据数值对数据进行排序


#### sort 示例


让我们看看 `sort` 的几个简单示例。


我们有一个 `list.txt` 的文件，包含逗号分隔的名称和数值。


首先让我们打印出文件内容并简单排序：



```
$ cat list.txt
Cieran Wilks, 9
Adelina Rowland, 4
Hayden Mcfarlnd, 1
Ananya Lamb, 5
Shyam Head, 2
Lauryn Fuents, 8
Kristian Felix, 10
Ruden Dyer, 3
Greyson Meyers, 6
Luther Cooke, 7

$ sort list.txt
Adelina Rowland, 4
Ananya Lamb, 5
Cieran Wilks, 9
Greyson Meyers, 6
Hayden Mcfarlnd, 1
Kristian Felix, 10
Lauryn Fuents, 8
Luther Cooke, 7
Ruden Dyer, 3
Shyam Head, 2

```

现在对数据进行倒序排序：



```
$ sort -r list.txt
Shyam Head, 2
Ruden Dyer, 3
Luther Cooke, 7
Lauryn Fuents, 8
Kristian Felix, 10
Hayden Mcfarlnd, 1
Greyson Meyers, 6
Cieran Wilks, 9
Ananya Lamb, 5
Adelina Rowland, 4

```

让我们打乱数据：



```
$ sort -R list.txt
Cieran Wilks, 9
Greyson Meyers, 6
Adelina Rowland, 4
Kristian Felix, 10
Luther Cooke, 7
Ruden Dyer, 3
Lauryn Fuents, 8
Hayden Mcfarlnd, 1
Ananya Lamb, 5
Shyam Head, 2

```

来看一点更复杂的。这次我们根据第二个字段，也就是数值对数据进行排序，并使用 `-o` 选项将输出保存到另一个文件中：



```
$ sort -n -k2 -t ',' -o sorted_list.txt list.txt
$ ls
   sorted_list.txt    list.txt
$ cat sorted_list.txt
Hayden Mcfarlnd, 1
Shyam Head, 2
Ruden Dyer, 3
Adelina Rowland, 4
Ananya Lamb, 5
Greyson Meyers, 6
Luther Cooke, 7
Lauryn Fuents, 8
Cieran Wilks, 9
Kristian Felix, 10

```

这里我们使用 `-n` 选项按数字顺序进行排序，`-k` 选项用来指定要排序的字段（在本例中为第 2 个字段），`-t` 选项指定分隔符或字段分隔符（逗号），`-o` 选项将输出保存到 `sorted_list.txt` 文件中。


### sed


`sed` 是一个流编辑器，用于过滤和转换输出中的文本。这意味着我们不需要对原文件进行修改，只需要对输出进行修改。如果需要，我们可以将更改保存到一个新的文件中。`sed` 提供了很多有用的选项用于过滤和编辑数据。


`sed` 的语法格式如下：



```
$ sed [OPTION] ‘PATTERN’ filename

```

sed 常用的一些选项：


* `-n` 取消默认输出
* `p` 打印指定的数据
* `d` 删除指定行
* `q` 退出 `sed` 脚本


#### sed 示例


我们来看看 `sed` 是如何运作的。我们从 `data` 文件开始，其中的字段表示编号、名称、年龄和操作系统。


如果行出现在特定的行范围内，该行将打印 2 次：



```
$ cat data
1    Vicky Grant      20   linux
2    Nora Burton    19   Mac
3    Willis Castillo   21  Windows
4    Gilberto Mack 30   Windows
5    Aubrey Hayes  17   windows
6    Allan Snyder    21   mac
7    Freddie Dean   25   linux
8    Ralph Martin    19   linux
9    Mindy Howard  20   Mac

$ sed '3,7 p' data
1    Vicky Grant      20   linux
2    Nora Burton    19   Mac
3    Willis Castillo   21  Windows
3    Willis Castillo   21  Windows
4    Gilberto Mack 30   Windows
4    Gilberto Mack 30   Windows
5    Aubrey Hayes  17   windows
5    Aubrey Hayes  17   windows
6    Allan Snyder    21   mac
6    Allan Snyder    21   mac
7    Freddie Dean   25   linux
7    Freddie Dean   25   linux
8    Ralph Martin    19   linux
9    Mindy Howard 20   Mac

```

这里的操作用单引号括起来，表示第 3 行和第 7 行，并且使用了 `p` 打印出符合匹配规则的数据。sed 的默认行为是在解析后打印每一行。这意味着由于使用了 `p` ，第 3 行到第 7 行打印了两次。


如何打印文件中特定的行？使用 `-n` 选项来消除在输出中不匹配的行：



```
$ sed -n '3,7 p' data
3    Willis Castillo     21    Windows
4    Gilberto Mack    30   Windows
5    Aubrey Hayes     17   windows
6    Allan Snyder       21   mac
7    Freddie Dean      25  linux

```

使用 ‘-n’ 仅仅只有第 3 行到第 7 行会被打印。


省略文件中的特定行。使用 `d` 从输出中删除行：



```
$ sed '3 d' data
1    Vicky Grant      20    linux
2   Nora Burton     19    Mac
4   Gilberto Mack  30    Windows
5   Aubrey Hayes   17    windows
6   Allan Snyder     21    mac
7   Freddie Dean    25   linux
8   Ralph Martin    19    linux
9   Mindy Howard  20   Mac

$ sed '5,9 d' data
1    Vicky Grant     20   linux
2   Nora Burton    19   Mac
3   Willis Castillo   21   Windows
4   Gilberto Mack 30   Windows

```

从文件中搜索特定的关键字：



```
$ sed -n '/linux/ p' data
7    Freddie Dean   25  linux
8    Ralph Martin   19   linux

$ sed -n '/linux/I p' data
1     Vicky Grant      20  Linux
7     Freddie Dean  25  linux
8     Ralph Martin   19  linux

```

在这些例子中，我们在 `/ /` 中使用了一个正则表达式。如果文件中有类似的单词，但大小写不一致，可以使用 `I` 使得搜索不区分大小写。回想一下，`-n` 删除了输出中不匹配的行。


替换文件中的单词：



```
$ sed 's/linux/linus/' data
1   Vicky Grant      20   Linux
2   Nora Burton    19   Mac
3   Willis Castillo   21   Windows
4   Gilberto Mack  30  Windows
5   Aubrey Hayes   17  windows
6   Allan Snyder     21  mac
7   Freddie Dean    25 linus
8   Ralph Martin    19  linus
9   Mindy Howard 20  Mac

```

这里 `s/ / /` 表示它是一个正则表达式。在两个 `/` 之间的就是定位的单词和需要替换的新单词。


### tr


`tr` 命令可以用来转换或删除字符。它可以将小写字母转换为大写字母，也可以将大写字母转换为小写字母，可以消除重复字符，也可以删除特定字符。


`tr` 的奇怪之处在于，它不同于 `wc`、`sort`、`sed` 那样接受文件作为输入。我们使用 `|` （管道符）为 `tr` 命令提供输入。



```
$ cat filename | tr [OPTION]

```

`tr` 命令使用的一些选项：


* `-d` 删除给定输入第一个集合中的指定字符，不做转换
* `-s` 将重复出现的字符替换为单个


#### tr 示例


现在让我们使用 `tr` 命令将 `letter` 文件中的所有小写字符转换为大写字符：



```
$ cat letter
Linux is too easy to learn,
And you should try it too.

$ cat letter | tr 'a-z' 'A-Z'
LINUX IS TOO EASY TO LEARN,
AND YOU SHOULD TRY IT TOO.

```

这里的 `a-z`、`A-Z` 表示我们想要将 `a` 到 `z` 范围内的小写字符转换为大写字符。


删除文件中的 `o` 字符：



```
$ cat letter | tr -d 'o'
Linux is t easy t learn,
And yu shuld try it t.

```

从文件中压缩字符 `o` 意味着如果 `o` 在文件中重复出现，那么它将会被删除并且只打印一次：



```
$ cat letter | tr -s 'o'
Linux is to easy to learn,
And you should try it to.

```

### 总结


这是使用 `wc`、`sort`、`sed`、`tr` 命令的快速演示。这些命令可以方便快捷的操作终端上的文本文件。你可以使用 `man` 命令来了解这些命令的更多信息。




---


via: <https://fedoramagazine.org/command-line-quick-tips-wc-sort-sed-and-tr/>


作者：[mahesh1b](https://fedoramagazine.org/author/mahesh1b/) 选题：[lujun9972](https://github.com/lujun9972) 译者：[perfiffer](https://github.com/perfiffer) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
Linux distributions are great to use and they have some tricks under their sleeves which users may not be aware of. Let’s have a look at some command line utilities which really come in handy when you’re the guy that likes to stick with the terminal rather than using a GUI.

We all know that using a terminal is more efficient to use the system. In case you are editing or playing with text files on a terminal then these tools will surely make your life easy.

For this article let’s have a look at *wc*, *sort*, *tr*, and *sed* commands.

**wc**

wc is a utility whose name stands for “word count”. As the name suggests it will count the lines, words or byte count from any file.

Let’s see how it works:

$ wcfilenamelines words characters filename

So in output we get the total number of newlines in the file, total number of words, total number of characters, and the filename.

To get some specific output we have to use options:

- -c To print the byte counts
- -l To print the newline counts
- -w To print the word counts
- -m To print the character counts

### wc demo

Let’s see it in action:

Here we start with a text file, ` loremipsm.txt`. First, we print out the file and then use

*wc*on it.

$ cat loremipsm.txtLinux is the best-known and most-used open source operating system. As an operating system, Linux is software that sits underneath all of the other software on a computer, receiving requests from those programs and replaying these requests to the computer's hardware.$ wc loremipsm.txt3 41 268 loremipsm.txt

Suppose I only want to see the byte count of the file:

$ wc -c loremipsm.txt268 loremipsm.txt

For the newline count of the file:

$ wc -l loremipsm.txt3 loremipsm.txt

To see the word count of the file:

$ wc -w loremipsm.txt41 loremipsm.txt

Now only the character count of the file:

$ wc -m loremipsm.txt268 loremipsm.txt

**sort**

The *sort* command is one of the most useful tools. It will sort the data in a file. Sorting is by either characters or numbers in ascending or descending order. It can also be used to sort or randomize the lines of files.

Using *sort* can be very simple. All we need to do is provide the name of the file.

$ sortfilename

By default it sorts the data in alphabetical order. One thing to note is that the *sort* command just displays the sorted data. It does not overwrite the file.

Some useful options for *sort*:

- -r To sort the lines in the file in reverse order
- -R To shuffle the lines in the file into random order
- -o To save the output in another file
- -k To sort as per specific column
- -t To mention the field separator
- -n To sort the data according to numerical value

### sort demo

Let’s use *sort* in some short demos:

We have a file, ` list.txt,` containing names and numeric values separated by commas.

First let’s print out the file and just do simple sorting.

$ cat list.txtCieran Wilks, 9 Adelina Rowland, 4 Hayden Mcfarlnd, 1 Ananya Lamb, 5 Shyam Head, 2 Lauryn Fuents, 8 Kristian Felix, 10 Ruden Dyer, 3 Greyson Meyers, 6 Luther Cooke, 7$ sort list.txtAdelina Rowland, 4 Ananya Lamb, 5 Cieran Wilks, 9 Greyson Meyers, 6 Hayden Mcfarlnd, 1 Kristian Felix, 10 Lauryn Fuents, 8 Luther Cooke, 7 Ruden Dyer, 3 Shyam Head, 2

Now sort the data in the reverse order.

$ sort -r list.txtShyam Head, 2 Ruden Dyer, 3 Luther Cooke, 7 Lauryn Fuents, 8 Kristian Felix, 10 Hayden Mcfarlnd, 1 Greyson Meyers, 6 Cieran Wilks, 9 Ananya Lamb, 5 Adelina Rowland, 4

Let’s shuffle the data.

$ sort -R list.txtCieran Wilks, 9 Greyson Meyers, 6 Adelina Rowland, 4 Kristian Felix, 10 Luther Cooke, 7 Ruden Dyer, 3 Lauryn Fuents, 8 Hayden Mcfarlnd, 1 Ananya Lamb, 5 Shyam Head, 2

Let’s make it more complex. This time we sort the data according to the second field, which is the numeric value, and save the output in another file using the -o option.

$ sort -n -k2 -t ',' -o sorted_list.txt list.txt$ lssorted_list.txt list.txt$ cat sorted_list.txtHayden Mcfarlnd, 1 Shyam Head, 2 Ruden Dyer, 3 Adelina Rowland, 4 Ananya Lamb, 5 Greyson Meyers, 6 Luther Cooke, 7 Lauryn Fuents, 8 Cieran Wilks, 9 Kristian Felix, 10

Here we used -n to sort in numerical order, -k to specify the field to sort (2 in this case) -t to indicate the delimiter or field-separator (a comma) and -o to save the output in the file *sorted_list.txt*.

**sed**

Sed is a stream editor that will filter and transform text in the output. This means we are not making changes in the file, only to the output. We can also save the changes in a new file if needed. Sed comes with a lot of options that are useful in filtering or editing the data.

The syntax for sed is:

$ sed[OPTION] ‘PATTERN’ filename

Some of the options used with sed:

- -n : To suppress the printing
- p: To print the current pattern
- d : To delete the pattern
- q : To quit the sed script

### sed demo

Lets see *sed* in action. We start with the file ` data` with the fields indicating number, name, age and operating system.

Printing the lines twice if they occur in a specific range of lines.

$ cat data1 Vicky Grant 20 Linux 2 Nora Burton 19 Mac 3 Willis Castillo 21 Windows 4 Gilberto Mack 30 Windows 5 Aubrey Hayes 17 windows 6 Allan Snyder 21 mac 7 Freddie Dean 25 linux 8 Ralph Martin 19 linux 9 Mindy Howard 20 Mac$ sed '3,7 p' data1 Vicky Grant 20 Linux 2 Nora Burton 19 Mac 3 Willis Castillo 21 Windows 3 Willis Castillo 21 Windows 4 Gilberto Mack 30 Windows 4 Gilberto Mack 30 Windows 5 Aubrey Hayes 17 windows 5 Aubrey Hayes 17 windows 6 Allan Snyder 21 mac 6 Allan Snyder 21 mac 7 Freddie Dean 25 linux 7 Freddie Dean 25 linux 8 Ralph Martin 19 linux 9 Mindy Howard 20 Mac

Here the operation is specified in single quotes indicating lines 3 through 7 and using ‘p’ to print the pattern found. The default behavior of sed is to print every line after parsing it. This means lines 3 through 7 appear twice because of the ‘p’ instruction.

So how can you print specific lines from the file? Use the ‘-n’ option to eliminate lines that do not match from the output.

$ sed -n '3,7 p' data3 Willis Castillo 21 Windows 4 Gilberto Mack 30 Windows 5 Aubrey Hayes 17 windows 6 Allan Snyder 21 mac 7 Freddie Dean 25 linux

Only lines 3 through 7 will appear using ‘-n’ .

Omitting specific lines from the file. This uses the ‘d’ to delete the lines from the output.

$ sed '3 d' data1 Vicky Grant 20 Linux 2 Nora Burton 19 Mac 4 Gilberto Mack 30 Windows 5 Aubrey Hayes 17 windows 6 Allan Snyder 21 mac 7 Freddie Dean 25 linux 8 Ralph Martin 19 linux 9 Mindy Howard 20 Mac$ sed '5,9 d' data1 Vicky Grant 20 Linux 2 Nora Burton 19 Mac 3 Willis Castillo 21 Windows 4 Gilberto Mack 30 Windows

Searching for a specific keyword in the file.

$ sed -n '/linux/ p' data7 Freddie Dean 25 linux 8 Ralph Martin 19 linux$ sed -n '/linux/I p' data1 Vicky Grant 20 Linux 7 Freddie Dean 25 linux 8 Ralph Martin 19 linux

In these examples we have a regular expression which appears in ‘/ /’. If we have similar words in the file but not with proper case then we use the “I” to make the search case insensitive. Recall that the -n eliminates the lines that do not match from the output.

Replacing the words in the file.

$ sed 's/linux/linus/' data1 Vicky Grant 20 Linux 2 Nora Burton 19 Mac 3 Willis Castillo 21 Windows 4 Gilberto Mack 30 Windows 5 Aubrey Hayes 17 windows 6 Allan Snyder 21 mac 7 Freddie Dean 25 linus 8 Ralph Martin 19 linus 9 Mindy Howard 20 Mac

Here ‘s/ / /’ denotes that it is a regex. The located word and then the new word to replace it appear between the two ‘/’.

**tr**

The *tr* command will translate or delete characters. It can transform the lowercase letters to uppercase or vice versa, eliminate repeating characters, and delete specific characters.

One thing weird about *tr* is that it does not take files as input like *wc*, *sort* and *sed* do. We use “|” (the pipe symbol) to provide input to the *tr* command.

$ catfilename| tr [OPTION]

Some options used with *tr*:

- -d : To delete the characters in first set of output
- -s : To replace the repeated characters with single occurrence

### tr demo

Now let’s use the *tr* command with the file ` letter` to convert all the characters from lowercase to uppercase.

$ cat letterLinux is too easy to learn, And you should try it too.$ cat letter | tr 'a-z' 'A-Z'LINUX IS TOO EASY TO LEARN, AND YOU SHOULD TRY IT TOO.

Here ‘a-z’ ‘A-Z’ denotes that we want to convert characters in the range from “a” to “z” from lowercase to uppercase.

Deleting the “o” character from the file.

$ cat letter | tr -d 'o'Linux is t easy t learn, And yu shuld try it t.

Squeezing the character “o” from the file means that if “o” is repeated in line then it will remove it and print it only once.

$ cat letter | tr -s 'o'Linux is to easy to learn, And you should try it to.

**Conclusion**

This was a quick demonstration of the *wc*, *sort*, *sed* and *tr* commands. These commands make it easy to manipulate the text files on the terminal in a quick and efficient way. You may use the *man* command to learn more about these commands.

## William gupton

This is great..quick and to the point

## James

Ooh, can I add my favourite use of sort?

sort | uniq -c | sort -n

For use on logfiles: use grep to select the lines you’re interested in, something like cut to select the resource you’re interested in (something like a user agent, a user, or a file), and then pipe that to sort | uniq -c | sort -n. Gives you a list of how often the resource turns up in the logfile, which gives you a pointer to where to start looking for further problems.

Worked example on a mail server with Exim installed:

grep -h ” <= ” /var/log/exim/main.log* | cut -d\ -f5 | cut -d@ -f2 | sort | uniq -ic | sort -n

(all one line.)

Which domains email us the most often?

## Daniel

What has happened that one needs to write a blog post to talk about basic Unix programs? Who are the targeted readers of this post?

This isn’t a good sign. If this is true that many Linux users don’t know about the shell, we are doing something wrong, the way they are introduced to the system needs to be rethinked.

## SigmaSquadron

It’s a good thing, IMO. Linux has always been behind macOS and Windows in terms of GUI usage, and if there’s a number of users who solely use the GUI as their primary method of interfacing with the system, it shows that the desktop front of Linux evolved past the need to share space with the CLI.

Besides, those users can always turn to the LFS manual to fully learn what makes Linux tick. It’s a good thing to learn new things on computing, but most of the time you just want a good GUI-only computer to get some work done.

I guess the way Linux works makes this possible. Distros like Fedora Workstation will probably never give much thought to the CLI, while distros targeted for more advanced users, like Arch, Gentoo, LFS or Slackware will pay less attention to providing a good GUI for newcomers. It’s all about different audiences and the choice to use what you want — be that a GUI-only distro, a mix of both interfaces, or a CLI-only distro.

## Darvond

Remember, not everyone is a Unix Guru or Amiga veteran. Most are probably washing ashore from the rocky shoals of MInt, Ubuntu, Pop-OS and other such things which will try their damnedest to hide the “underbelly”.

And given that most UNIX were coded with the constraints of punchcards and 300 baud terminals, there is a lot of “inside baseball”. especially given between aa and zz there are 676 potential combinations, and that’s not counting switches. Even something as simple as ls goes from -a to -z.

Is cal Calculate? Nope. It’s calendar.

Demystifying the command line is always good.

## lucky thousand

https://xkcd.com/1053/

## rex fury

Tricks UP their sleeves 🙂

## rex fury

I love Linux from the command line! Screen for multiple consoles, Midnight Commander for files, No, I really don’t use Vim that much. 🙂

## xenlo

there is a mistake in “wc demo” section, the last code box is the copy-paste of the previous one. It should be

in place of

## Gregory Bartholomew

Thanks xenlo. I’ve made the correction.

## Ron Olson

wc has another awesome benefit; because of pipes, you can pipe output to wc which works great for finding out how many items are in a directory, .e.g., “ls -l | wc -l”

## james miller

Nice introduction to some handy commands. I am fairly sure that all the commands can be used as streams, with pipes, certainly sed and wc can.

I am currently using :

ls |wc -l to list how many files are in a directory, for example.

## y0umu

isn’t it

?

## Gregory Bartholomew

Some programs vary their output depending on whether their output is connected to an interactive terminal or to a pipe. ls is one of them. Try it:

## Jasper Hartline

When doing %post processing in rpmbuild sessions to build an RPM package on Fedora I’ve used 6 command utilities in line with pipes to get what I need its so awesome the pipe is the first resort.

## You Really Don't Want to Know

perl

## Sampsonf

Thanks for sharing.

For sed, when it will modify the data file, when it will modify the output only?

## Wolfgang Marx

Great Overview! Thanks, learned something again:)

## edier88

Excellent article.

A full tutorial of awk and sed would be nice too.

Thank you!

## Jared G

I second this! Giving a “full” tutorial within a single article is surely impossible, but there are some common use cases that would be helpful to cover.

Whenever performing some rote task in my everyday administrative life, I ask myself, “Can I automate this somehow?” Often, I wind up writing a shell script to just that. In my experience, this is one of the best ways to deeply learn your way around tools like these.

## Ok5ieGh3

The tr-example makes useless use of cat, instead of cat letter | tr one should use tr < letter

## Nildo

Excelente postagem!

Thank you!

## Phoenix

When demonstrating “tr” (and “sed”), I have the feeling that “cut” should have been mentioned alongside with it as it is as easy and useful as well. As with all mentioned programs, it works tremendously well capturing (piping) the output of the previous command and further refining the output.

Example:

cut -d”:” -f1,3-4,6 /etc/passwd

“-d” uses delimiter (in this case “:”)

“-f” display only fields delimited by delimiter (here: fields 1, 3 to 4 and 6)

## Leslie Satenstein, Montreal,Que,Canada

This article is going to be my cheat sheet. In a few well designed examples, I have learned how to make better use of, or infact, consider using the above described command line tools.,

Thank You !!

## Ian

There is an error in the sed demo.

The example file (data) has ‘linux’ in the first line.

Part way through the demonstration, that line has changed to ‘Linux’ so that the use of case insensitive can be shown

## Gregory Bartholomew

Thanks Ian. I’ve attempted to correct the example file so that the first line contains ‘Linux’ from the beginning.