我想删除所有带3个加号的行:
+++ 3 plus signs
+ 1 plus sign
+++ 3 plus signs
下面是我的sed命令,在行首后面转义加号
sed '/^\+\+\+/d' -> This erase all lines
sed '/^+++/d' -> This works and show only the 1 plus sign line
为什么?在转义加号时有什么问题吗?
我想用命令终端开始一首歌。
在我的目录中,当我这样做时,它会打印出来
ls
AlbumArtSmall.jpg
Folder.jpg
[SongsPK.info] Table No 21 - 02 - Man Mera.mp3
[Songs.PK] Table No 21 - 01 - O Sajna.mp3
[Songs.PK] Table No 21 - 02 - Man Mera.mp3
我想播放第三首歌,所以我写了这个命令
ls |sed -n "3p"|vlc
但它不是播放歌曲,vlc播放器只是打开,但不播放。如何解决这个问题?
在尝试下面的答案后,如下所示
ls|s
这在任何Linux上都能很好地工作:
$ echo foo bar | sed -n '/foo/{/bar/{;p;}}'
foo bar
但在OSX古老的BSD变体上却失败了:
❯ echo foo bar | sed -n '/foo/{/bar/{;p;}}'
sed: 1: "/foo/{/bar/{;p;}}": extra characters at the end of } command
我是不是错过了什么魔法咒语?有办法用便携的方式写吗?
我不想恢复到grep | grep | grep命令的管道。
更新:低代表在这里,
我正在尝试在MacOSX终端上运行这个命令,它最初是打算在Linux上运行的。
sed '1 i VISPATH=/mnt/local/gdrive/public/3DVis' init.txt >> ~/.bash_profile
但它给了我一个错误:
command i expects \ followed by text.
有没有办法修改上面的命令,使其在MacOSX终端上工作
我试图用以下命令删除行首的数字:
sed -i 's/^\d*\t//' sea_news_2020_corpus.txt
这一行看上去如下:
809940 The sea will be moderate in the Arabian Gulf and slight to moderate in Oman.
为什么这不管用?试了很长时间
尝试使用Sed的美丽,所以我不需要手动更新几百个文件。我会注意到我的雇主只允许使用Win8 (joy),所以我整天使用Cygwin,直到我可以在家里使用我的Linux盒。
以下内容适用于Linux (bash)命令行,而不是Cygwin
> grep -lrZ "/somefile.js" . | xargs -0 -l sed -i -e 's|/somefile.js|/newLib.js|g'
sed: can't read ./testTarget.jsp: No such file or directory
# works
> s
我正在尝试使用sed,但我希望在Linux和Mac下都能正常运行。目前,我有这样的事情:
if test -f ${GENESISFILE};
then
echo "Replacing ..."
sed -i '' "s/ADDRESS/${ADDRESS}/g" ${GENESISFILE}
else
echo "No such file"
fi
现在,重点是使用-i ''部件,它在Mac下正常运行,但在Linux下不运行,如果我删除它,那么它在Mac下就不能工作。怎样才能使其跨平台兼容呢
什么应用程序可以和沙扎姆或声猎犬在安卓上做同样的工作呢?
沙扎姆 for windows和MacOs,我不喜欢葡萄酒,而且它是商业化的。您可以验证大约2-5首歌曲,必须支付继续.
SoundHound --紧密移动Os的应用程序。
Linux/Ubuntu的哪种应用程序可以做到同样的功能呢?
$ soundhound song.mp3
The Beatles - Let it be - imdb index#
我发现了这个问题,但答案只是关于mp3标签:申请寻找歌曲名称
我想使用sed在行号指定的行首插入一个单词。这个oneliner效果很好:
line="this is my line"; newfile=`sed "6s/.*/word $line/" /opt/file.txt`
但我的问题是,当我在脚本中运行代码时,它会抛出一个错误:
line="this is my line"
newfile=`sed "6s/.*/word $line/" $FILE_PATH`
sed: -e expression #1, char 91: unknown option to `s'
Sed
在linux中,我们可以运行sort命令来对文件内容进行排序,但在我的示例中,我有以下文件(THANKS.txt):
These people have contributed to OSN Envoy. We always try to keep this list updated and correct.
If you notice that your name is not listed here, then feel free to contact us.
Ar Rakin
Peter Williamson
David Brook
Bill Natt
此文件包含软件项目贡献者的列表
Linux期望代码段:
set info "IP address 2.2.2.2 mask x\n"
set OLD_INTERNET_IP "2.2.2.2"
set NEW_INTERNET_IP "1.1.1.1"
set newinfo [exec echo $info | sed '{s/${OLD_INTERNET_IP}/${OLD_INTERNET_IP}/}']
send_user $info
send_user $newinfo
我正在尝试将info中的2.2.2.2替换为1.1.1.1并设置为ne
我有一个文件,里面有几行。
如果其中包含一些关键字,我想在这些行中添加一个前缀。
我该怎么做?谢谢!
示例:
我想将"###"添加到行首带有"Hello“的行中:
当前此文件有:
This is the beginning.
Hello I am Simon.
This is a simple line;
Hello Mike.
This is another line.
我想将此文件更改为:
This is the beginning.
###Hello I am Simon.
This is a simple line;
###Hello Mike.
This is
如何让sed替换前一行?我只看到了delete,insert行的例子,但实际上我需要的是,只有在满足了下一行的条件时,我才会对当前行进行替换。
我的示例文件如下所示
$ /bin/cat test
Cygwin
Cygwin is a cool emulator for Linux on Windows.
Unix
Maybe
the coolest environment?
Linux
Is also one of the best environments
Solaris
Why did Sun feel copying Java into Unix would matter?
AI
我有一个文件trial.txt包含
This can stay
// but this
/ and this
// must go
I will be happy
删除在其他情况下使用的前导#
os.system(" sed '/^#.*/d' trial.txt > start.txt ")
所以删除//我用了
os.system(" sed '/^//.*/d' trial.txt > start.txt ")
但这会造成错误
sed: 1: "/^//.*/d": invalid command
我的输入文件是
cat random.txt
hello my name is hello
当我使用egrep '^hello|hello$ random.txt时
结果是hello my name is hello
我该如何修改该命令以输出如下所示的内容
hello my name is
或
my name is hello
如果这两个单词在同一行上,则从行首或行尾开始,基本上删除相同的单词?