什么是换行符 - 的'\\ n' [英] What is newline character -- '\n'

查看:228
本文介绍了什么是换行符 - 的'\\ n'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个非常基本的概念,但是这是我从来没有能够阐明那么好。我想尝试拼一下,看看我出错。

This is a very basic concept, but something I have never been able to articulate that well. and I would like to try to spell it and see where I go wrong.

如果我有,我会怎样定义一个换行符。说,如果我在创建UNIX(或窗口),一个新的文件,然后进行文件通过插入称为新行字符文件中的一个特殊字符存放行结束的信息。如果是这样,什么是它的ASCII值?我记得,在C程序中,我已经检查了对价值的'\\ n'读字。而为什么这混乱的2个字符重新行的字符present结束。

If I have to, how would I define a "newline character". say if I create a new file in unix(or windows), then does the file store the "end of line" information by inserting a special character in the file called as "new line character". If so, what is its ascii value? I remember that in C programs, I have checked for the read character against the value '\n' . And why this confusing 2 characters to represent end of line characters..

bash$ cat states
California
Massachusetts
Arizona

说,我要插入的行之间的一个空行,并希望表单的输出:
    所需的输出:

Say, I want to insert one line space between the lines and want an output of the form: Desired output:

California

Massachusetts

Arizona

bash$sed -e 's/\n/\n\n/g' states  does not work.

为什么我不能把新行字符这里就像我会像对待其他任何字符并运行类似上面的命令。 (据我所知,也许有人会说,这是SED语法的问题,但将来有请解释直觉背后不允许这一点,这样我就可以摆脱我的困惑。

Why can't I treat "new line character" here just as I would treat any other character and run something like above command. (I understand that one might say that this is a matter of syntax of sed, but could one please explain the intuition behind not allowing this, so that I can get rid of my confusion.

同样,vim编辑器里面,我无法使用:%s / \\ n / \\ n \\ n / g的。为什么会这样?

Similarly, inside the vim editor, I can not use :%s/\n/\n\n/g . Why so?

我是否需要通过VIM内sed和使用反斜线进一步外泄\\ n?

Do I need to further escape \n by using a backslash in sed and from within vim?.

谢谢,

Jagrati

推荐答案

从<一个href=\"http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/sed.1.html\"><$c$c>sed手册页:

通常情况下,周期性的sed副本一行输入,不包括其终止换行符,进入模式空间,(除非有东西D功能后左一),适用于所有的命令与选择模式地址空间,副本模式空间到标准输出,追加一个换行符,并删除模式空间。

Normally, sed cyclically copies a line of input, not including its terminating newline character, into a pattern space, (unless there is something left after a "D" function), applies all of the commands with addresses that select that pattern space, copies the pattern space to the standard output, appending a newline, and deletes the pattern space.

它的经营上不换行present行,所以该模式在你那里永远不能比拟的。你需要做别的事情 - 就像对阵 $ (尾线)或 ^ (启动的直插式)。

It's operating on the line without the newline present, so the pattern you have there can't ever match. You need to do something else - like match against $ (end-of-line) or ^ (start-of-line).

下面的东西,对我工作的例子:

Here's an example of something that worked for me:

$ cat > states
California
Massachusetts
Arizona
$ sed -e 's/$/\
> /' states
California

Massachusetts

Arizona

我输入后字面换行符 \\ SED 行。

这篇关于什么是换行符 - 的'\\ n'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆