给定这样的文件名:
/the/path/foo.txt
bar.txt
Run Code Online (Sandbox Code Playgroud)
我希望得到:
foo
bar
Run Code Online (Sandbox Code Playgroud)
为什么这不起作用?
#!/bin/bash
fullfile=$1
fname=$(basename $fullfile)
fbname=${fname%.*}
echo $fbname
Run Code Online (Sandbox Code Playgroud)
什么是正确的方法呢?
我有如下图.它是使用此命令创建的:
library(ggplot2)
df <- data.frame(cond = factor(rep(c("A", "B"), each = 200)),
rating = c(rnorm(200), rnorm(200, mean=.8)))
ggplot(df, aes(x=rating, fill=cond)) +
geom_density(alpha = .3) +
xlab("NEW RATING TITLE") +
ylab("NEW DENSITY TITLE")
Run Code Online (Sandbox Code Playgroud)
现在,接下来我要做的事情就是修改图例标题从COND进入新里程TITLE.
所以我所做的只是添加以下行添加上面代码的结尾:
+labs(colour="NEW LEGEND TITLE")
Run Code Online (Sandbox Code Playgroud)
但它不起作用.什么是正确的方法呢?
我有一个磁盘驱动器,inode使用率为100%(使用df -i
命令).但是,在大幅删除文件后,使用率仍为100%.
这样做的正确方法是什么?
如果磁盘空间使用量较少的磁盘驱动器可能比磁盘空间使用率较高的磁盘驱动器具有更高的Inode使用率,那怎么可能?
如果我压缩很多文件会减少使用的inode数量吗?
我有一个格式如下的数据:
foo<tab>1.00<space>1.33<space>2.00<tab>3
Run Code Online (Sandbox Code Playgroud)
现在我尝试逐渐根据最后一个字段对文件进行排序.我尝试了以下命令,但它没有像我们预期的那样排序.
$ sort -k3nr file.txt # apparently this sort by space as delimiter
$ sort -t"\t" -k3nr file.txt
sort: multi-character tab `\\t'
$ sort -t "`/bin/echo '\t'`" -k3,3nr file.txt
sort: multi-character tab `\\t'
Run Code Online (Sandbox Code Playgroud)
什么是正确的方法呢?
这是样本数据.
我有一个文件,其中包含我想用tar存档的文件列表.我们称之为mylist.txt
它包含:
file1.txt
file2.txt
...
file10.txt
Run Code Online (Sandbox Code Playgroud)
有没有办法可以发出mylist.txt
作为输入的TAR命令?就像是
tar -cvf allfiles.tar -[someoption?] mylist.txt
Run Code Online (Sandbox Code Playgroud)
所以它就像我发出这个命令一样:
tar -cvf allfiles.tar file1.txt file2.txt file10.txt
Run Code Online (Sandbox Code Playgroud) 我尝试了以下代码(test_seaborn.py
):
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
matplotlib.style.use('ggplot')
import seaborn as sns
sns.set()
df = sns.load_dataset('iris')
sns_plot = sns.pairplot(df, hue='species', size=2.5)
fig = sns_plot.get_figure()
fig.savefig("output.png")
#sns.plt.show()
Run Code Online (Sandbox Code Playgroud)
但我得到这个错误:
Traceback (most recent call last):
File "test_searborn.py", line 11, in <module>
fig = sns_plot.get_figure()
AttributeError: 'PairGrid' object has no attribute 'get_figure'
Run Code Online (Sandbox Code Playgroud)
我希望决赛output.png
将会存在,看起来像这样:
我该如何解决这个问题?
我有多个文件,我想连接cat
.让我们说吧
File1.txt
foo
File2.txt
bar
File3.txt
qux
Run Code Online (Sandbox Code Playgroud)
我想连接,以便最终文件看起来像:
foo
bar
qux
Run Code Online (Sandbox Code Playgroud)
而不是平常 cat File*.txt > finalfile.txt
foo
bar
qux
Run Code Online (Sandbox Code Playgroud)
什么是正确的方法呢?
我有以下数据框和变量名称"foo"
;
> foo <-c(3,4);
Run Code Online (Sandbox Code Playgroud)
我想要做的是转换"foo"
成一个字符串.所以在函数中我不必重新创建另一个额外的变量:
output <- myfunc(foo)
myfunc <- function(v1) {
# do something with v1
# so that it prints "FOO" when
# this function is called
#
# instead of the values (3,4)
return ()
}
Run Code Online (Sandbox Code Playgroud) 我有gzip文件列表:
file1.gz
file2.gz
file3.gz
Run Code Online (Sandbox Code Playgroud)
有没有办法将这些文件连接或gzipping到一个gzip文件 而不必解压缩?
实际上,我们将在Web数据库(CGI)中使用它.Web将从用户接收查询并基于查询列出所有文件,并将它们以批处理文件的形式呈现给用户.
我有多行以下数据:
foo
bar
qux
zuu
sdf
sdfasdf
Run Code Online (Sandbox Code Playgroud)
我想要做的是用一行和逗号分隔它们:
foo,bar,qux,zuu,sdf,sdfasdf
Run Code Online (Sandbox Code Playgroud)
什么是最好的unix单线程呢?