Questions tagged «text-processing»

通过程序,脚本等操作或检查文本




2
删除所有在定界符前没有n个字符的行
我有一个很长的文本文件(从此处开始),其中应包含6个十六进制字符,然后是一个“ break”(显示为一个字符,在下面的代码降价中似乎无法正确显示),然后是几个单词: 00107B Cisco Systems, Inc 00906D Cisco Systems, Inc 0090BF Cisco Systems, Inc 5080 Cisco Systems, Inc 0E+00 ASUSTek COMPUTER INC. 000C6E ASUSTek COMPUTER INC. 001BFC ASUSTek COMPUTER INC. 001E8C ASUSTek COMPUTER INC. 0015F2 ASUSTek COMPUTER INC. 2354 ASUSTek COMPUTER INC. 001FC6 ASUSTek COMPUTER INC. 60182E ShenZhen Protruly Electronic …


4
如何使用grep命令将字符串搜索放入if语句?
我想在两个文件中搜索多个字符串。如果在两个文件中都找到一个字符串,则进行处理。如果仅在一个文件中找到一个字符串,则进行另一件事。 接下来是我的命令: ####This is for the affirmative sentence in both files if grep -qw "$users" "$file1" && grep -qw "$users" "$file2"; then ####This is for the affirmative sentence in only one file, and negative for the other one if grep -qw "$users" "$file1" ! grep -qw "$users" "$file2"; then 否定和确认声明的正确方法吗?pd我正在使用KSH …

8
检查文件的所有行是否唯一
我有一个包含以下内容的文本文件: This is a thread 139737522087680 This is a thread 139737513694976 This is a thread 139737505302272 This is a thread 139737312270080 . . . This is a thread 139737203164928 This is a thread 139737194772224 This is a thread 139737186379520 我如何确定每一行的唯一性? 注意:目的是测试文件,如果存在重复的行,则不要修改它。

3
如何使用grep搜索带有两个单词之一而不是两个单词的行?
我想在文本文件中搜索带有'word1'XOR'word2'的行。因此,它应该输出带有word1,word2的行,但不输出带有这两个单词的行。我想使用XOR,但是我不知道如何在linux命令行中编写它。 我试过了: grep 'word1\|word2' text.txt grep word1 word2 text.txt grep word1 text.txt | grep word2 grep 'word1\^word2' text.txt 还有更多,但没有成功。


7
如何修复在错误的地方折断的线?
我的文本文件如下所示: This is one sentence that is broken. However this is a good one. And this one is somehow, broken into many. 我想删除任何行的尾随换行符,其后是以小写字母开头的行。 所以这应该是: This is one sentence that is broken. However this is a good one. And this one is somehow, broken into many. 我怎样才能做到这一点? 编辑:这里有一些非常好的答案,但是我选择接受第一个可行且最早的答案。非常感谢大家!

9
更改文件中的行顺序
我正在尝试更改特定模式下的行顺序。使用包含多行(例如99行)的文件。对于每三行,我希望第二行是第三行,第三行是第二行。 例。 1-输入: gi_1234 My cat is blue. I have a cat. gi_5678 My dog is orange. I also have a dog. ... 2-输出: gi_1234 I have a cat. My cat is blue. gi_5678 I also have a dog. My dog is orange. ...

7
如何获取输入文本文件的第一行,同时从文本文件中删除该行
如何从文本文件中删除输入文本文件的第一行? 如果我有一个文本文件,/myPathToTheFile.txt这样 ► put returns between paragraphs ► for linebreak add 2 spaces at end ► _italic_ or **bold** 我想将此行作为输出 ► put returns between paragraphs 我的文本文件现在应该像这样 ► for linebreak add 2 spaces at end ► _italic_ or **bold*

5
在Solaris中,“ sed -i”命令是否可以替代?
我的项目中有一项要求,就是将文件中的某些现有文本替换为foo其他文本,例如fooofoo: abc.txt name foo foo1 所以我尝试了: sed -i "s/foo/fooofoo/g" abc.txt 但是我得到这个错误: sed:非法选项- i 我在手册中发现必须使用: sed -i\ "s/foo/fooofoo/g" abc.txt 但是,这也不起作用。 我发现,替代品perl和awk也,但在Solaris中的解决方案sed,将不胜感激。 我正在使用此版本的bash: GNU bash版本3.2.57(1)-发行版(sparc-sun-solaris2.10)


1
如何根据字段的一部分对文件进行排序
我想对文件进行排序: D104HN-D104HA 8.320 4.521 1.69e+05 -- D104HN-D104HB* 8.320 2.823 2.93e+05 -- A90HB#-A90HA 1.655 4.207 7.12e+05 -- A90HB#-F91HA 1.653 4.411 8.59e+04 -- A114HB#-A114HA 1.253 4.098 7.67e+05 -- A114HB#-R111HA 1.251 3.929 1.76e+05 -- A114HB#-W110HA 1.253 4.451 3.68e+04 -- F91HE*-F91HZ 7.237 7.122 7.85e+05 -- F91HE*-K92HA 7.242 3.910 4.88e+04 -- 并得到这个 A90HB#-A90HA 1.655 4.207 …

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.