我需要多次删除包含某个字符串的文件中的所有行,例如,如果我的文件如下所示:
This is a test toRemove first line
This is a test toRemove second line toRemove
应该生成一个类似于只有第一行的文件
This is a test toRemove first line
我正在尝试从命令行在linux上执行此操作,并尝试使用grep或sed,如下所示
grep -d "toRemove.*toRemove" myFile > myOtherFile
sed '/\toRemove.*toRe
这是我的样本文件
user@linux:~$ cat file.txt
Line 1
Line 2
Line 3
Line 4
Line 5
user@linux:~$
我可以用grep -A2 'e 2' file.txt打印第2-4行。
user@linux:~$ grep -A2 'e 2' file.txt
Line 2
Line 3
Line 4
user@linux:~$
我也可以用grep -n打印出行号。
user@linux:~$ grep -nA2 'e 2' file.txt
2:Line 2
3-Line 3
4
我有一个文本文件,其中包含以下文本。
/* a comment line in a C program */
printf("It is /* NOT a comment line */\n");
x = 5; /* This is an assignment, not a comment line */
[TAB][SPACE] /* another empty comment line here */
/* another weird line, but not a comment line */ y = 0;
我希望删除以/*开头的行,以*/结尾的行仅使用linu
使用linux,我希望搜索字符串Blah的文本文件,然后返回包含字符串的行完整行和模式后面的所有行,直到包含单词Failed的一行为止。
例如,
Test Case Name "Blah"
Error 1
Error 2
Error 3
Failed
Test Case Name "Foo"
Pass
Test Case Name "Red"
Pass
在上面,我想搜索"Blah",然后返回:
Test Case Name "Blah"
Error 1
Error 2
Error 3
一直到线Failed。Blah
如何使用sed来查找linux这个词的行?稍后会用linux这个词显示第10行吗?前:
cat file | sed -e '/linux/!d' -e '10!d' ### I can not display the first 10 lines of the word linux
cat file | sed '/linux/!d' | sed '10!d' ### It is well
如何使它与一个sed一起工作?
cat file | sed -e '/linux/!d; ...?; 10!d'
.?-
我试图弄清楚每个字在使用linux的文件中发生了多少次。
通过使用下面的代码,我已经将文件中的每个单词放到了一个新行中。
sed -i 's/ /\n/g' books2
我现在正试图用空格替换单词的开头和结尾,因为有些单词包含标点符号。我目前正在使用下面的代码来完成这个任务,但是它似乎不起作用。一旦我有了这个命令,我将能够运行一个命令,它将对所有单词进行计数,并返回所有单词的计数列表。有人能纠正我如何删除标点符号吗?
sed -i 's/\([^[:alpha:]]\)$//' books2 #this is my attempt to remove the
将此视为文件:
M ../.gitlab-ci.yml
M ../force-app/main/ui/classes/test.cls
A ../pmd/get_diff_branches.sh
?? ../assets/server.key
?? ./
我正在逐行删除所有的额外字符如下:
sed /^D/d diff.txt | sed 's/^..//' | sed /^force-app/p | sed /^force-app\\/package\.xml/d | sed 's/.*\ ->\ //' > temp.txt
这样做之后,文
我的文件包含以下几行
File.txt
Unix is good
Linux and unix is different?
Linux is also good, then what about unix?
这里我要输出
(1st line blank)
Linix and
Linux is also good, then what about
在这里vi命令或任何其他命令都会给出这个输出?搜索特定的单词,如果这是对的话,然后删除那个词,然后删除该行中的所有单词。