小编Shi*_*wal的帖子

从bash中的日期减去天数

我想从bash中的日期中减去"天数".我正在尝试这样的事情..

echo $dataset_date #output is 2013-08-07

echo $date_diff #output is 2   

p_dataset_date=`$dataset_date --date="-$date_diff days" +%Y-%m-%d` # Getting Error
Run Code Online (Sandbox Code Playgroud)

linux bash shell

39
推荐指数
4
解决办法
7万
查看次数

如何在Python中使用连接固定字符串和变量

我想在主题中包含文件名'main.txt',因为我从命令行传递文件名.但这样做会出错

python sample.py main.txt #running python with argument 

msg['Subject'] = "Auto Hella Restart Report "sys.argv[1]  #line where i am using that passed argument
Run Code Online (Sandbox Code Playgroud)

python string-concatenation

27
推荐指数
6
解决办法
16万
查看次数

如何创建动态变量并为其赋值?

我正在尝试创建一个动态变量并分配100给它

#!/bin/bash
.
.   
active_id=$p_val 
flag_$active_id=100
Run Code Online (Sandbox Code Playgroud)

但是我这样做会有错误,有什么帮助吗?

linux bash shell

12
推荐指数
2
解决办法
2万
查看次数

如何只获取文件的行数

如何在linux中获取文件的行数?

我只想要行数,而不是文件名.
我想在一个命令中完成它,没有grep或其他实用程序.

wc -l sample.txt   
Run Code Online (Sandbox Code Playgroud)

产量

5 sample.txt
Run Code Online (Sandbox Code Playgroud)

期望的输出

5
Run Code Online (Sandbox Code Playgroud)

linux bash

6
推荐指数
1
解决办法
6516
查看次数

如何在 crontab 中使用 tee 命令

我在 crontab 中放置了一个作业,每 2 小时运行一次,我还希望将 bash 输出的日志文件放在一个单独的文件中。

输入:

0 0-23/2 * * * /tmp/sample.sh | tee /tmp/logfile_extract_$(date '+%Y-%m-%d-%H').txt  
Run Code Online (Sandbox Code Playgroud)

输出:

/bin/sh: -c: line 0: unexpected EOF while looking for matching `''
/bin/sh: -c: line 1: syntax error: unexpected end of file
Run Code Online (Sandbox Code Playgroud)

linux bash shell cron tee

5
推荐指数
1
解决办法
6695
查看次数

如何在Bash脚本中运行sudo命令?

我想运行以下示例bash脚本,该脚本需要命令的sudo密码

#!/bin/bash
kinit #needs sudo password
vi hello.txt  
Run Code Online (Sandbox Code Playgroud)

在运行上面的脚本时,它要求输入密码.
我如何在命令本身中传递用户名和密码,还是有更好的方法可以跳过在脚本中传递密码?

bash shell

5
推荐指数
3
解决办法
2万
查看次数

使用tee命令创建特定于时间的日志文件

我正在使用'tee'命令将我的shell程序的日志重定向到一个文件中.

我的要求是使用文件名附加当前日期和时间.

sh sample.sh | tee logfile_$date.txt #sample command
Run Code Online (Sandbox Code Playgroud)

输出日志文件:

logfile_2013-08-22-14.txt  #yyyy-mm-dd-hh format
Run Code Online (Sandbox Code Playgroud)

我怎样才能实现它?

bash shell tee

2
推荐指数
1
解决办法
3452
查看次数

仅当存在于bash中时如何从文件中删除标题?

我有这个示例文件。我想删除该文件的第一行(标题),仅当它(标题)使用 bash 存在时。

id name job_id
1 john 25
2 adam 45
3 paul 75
Run Code Online (Sandbox Code Playgroud)

linux bash shell sed

2
推荐指数
1
解决办法
2239
查看次数

如何在datetime和float上进行插值

我正在使用scipy在时间序列上进行1d插值.我的x轴数据是日期时间格式,y轴是浮点数,如:

3/15/2012 16:00:00  32.94
3/16/2012 16:00:00  32.95
3/19/2012 16:00:00  32.61
Run Code Online (Sandbox Code Playgroud)

现在在斜率计算期间slope = (y_hi-y_lo) / (x_hi-x_lo)我得到的错误TypeError: unsupported operand type(s) for /: 'float' and 'datetime.timedelta'是一个明显的错误.有人能指出我正确的方向,如何处理它?

python interpolation scipy python-2.7

1
推荐指数
1
解决办法
4268
查看次数

使用文件内容在python中创建嵌套列表

我有一个这种格式的文本文件sample.txt(空格分隔)

12 john E 44 L
13 adam D 78 L
14 tue E 98 L
Run Code Online (Sandbox Code Playgroud)

我想将此文件转换为嵌套列表

table_data = [
        [12, 'john', 'E', 44, 'L'],
        [13, 'adam', 'D', 78, 'L'],
        [14, 'tue', 'E', 98, 'L'],
]
Run Code Online (Sandbox Code Playgroud)

我该怎么做 ?

python parsing list nested-lists

0
推荐指数
1
解决办法
1255
查看次数

如何使用sklearn库对朴素贝叶斯进行文本分类?

我正在尝试使用朴素贝叶斯文本分类器进行文本分类.我的数据采用以下格式,根据问题和摘录,我必须决定问题的主题.培训数据有超过20K的记录.我知道SVM会是一个更好的选择,但我想使用sklearn库Naive Bayes一起使用.

{[{"topic":"electronics","question":"What is the effective differencial effective of this circuit","excerpt":"I'm trying to work out, in general terms, the effective capacitance of this circuit (see diagram: http://i.stack.imgur.com/BS85b.png).  \n\nWhat is the effective capacitance of this circuit and will the ...\r\n        "},
{"topic":"electronics","question":"Outlet Installation--more wires than my new outlet can use [on hold]","excerpt":"I am replacing a wall outlet with a Cooper Wiring USB outlet (TR7745).  The new outlet has 3 wires coming out of it--a black, a white, …
Run Code Online (Sandbox Code Playgroud)

python machine-learning scikit-learn text-classification naivebayes

0
推荐指数
1
解决办法
2215
查看次数