小编Hat*_*kNZ的帖子

Windows中的`tr`命令是什么?

trLinux中命令的Windows等价物是什么?

例如,tr可以用换行符替换所有冒号.这可以在Windows中完成吗?

$ echo $PATH | tr ':' '\n'
/usr/local/bin
/usr/bin
Run Code Online (Sandbox Code Playgroud)

linux windows cmd tr

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

awk +如何在列中找到重复项?

如何在列中找到重复项?

$ head countries_lat_long_int_code3.csv | cat -n
     1  country,latitude,longitude,name,code
     2  AD,42.546245,1.601554,Andorra,376
     3  AE,23.424076,53.847818,United Arab Emirates,971
     4  AF,33.93911,67.709953,Afghanistan,93
     5  AG,17.060816,-61.796428,Antigua and Barbuda,1
     6  AI,18.220554,-63.068615,Anguilla,1
     7  AL,41.153332,20.168331,Albania,355
     8  AM,40.069099,45.038189,Armenia,374
     9  AN,12.226079,-69.060087,Netherlands Antilles,599
    10  AO,-11.202692,17.873887,Angola,244
Run Code Online (Sandbox Code Playgroud)

例如,这在第5列中有重复.

     5  AG,17.060816,-61.796428,Antigua and Barbuda,1
     6  AI,18.220554,-63.068615,Anguilla,1
Run Code Online (Sandbox Code Playgroud)

如何查看此文件中的所有其他内容?

我知道我可以这样做:

awk -F, 'NR>1{print $5}' countries_lat_long_int_code3.csv | sort
Run Code Online (Sandbox Code Playgroud)

我可以看一眼,看看是否有重复,但是有更好的方法吗?

或者我可以这样做:找出完全可能存在的方法

$ awk -F, 'NR>1{print $5}' countries_lat_long_int_code3.csv | sort | wc -l
210
Run Code Online (Sandbox Code Playgroud)

找出有多少独特的值

$ awk -F, 'NR>1{print $5}' countries_lat_long_int_code3.csv | sort | uniq | wc -l
183
Run Code Online (Sandbox Code Playgroud)

因此,最多有27(210-183)个重复.

EDIT1

我想要的输出将是如下,基本上所有列,但只显示重复的行: …

awk

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

R +使用regex + gsub将整数转换为hh:mm格式

interval是25小时内5分钟间隔的子集

> interval
 [1]   45   50   55  100  105  110  115  120  125  130  135 2035 2040 2045 2050 2055 2100 2105 2110 2115 2120 2125
Run Code Online (Sandbox Code Playgroud)

我想插入:一个时间fomat,我可以转换为时间格式

> gsub('^([0-9]{1,2})([0-9]{2})$', '\\1:\\2', interval)
 [1] "45"    "50"    "55"    "1:00"  "1:05"  "1:10"  "1:15"  "1:20"  "1:25"  "1:30"  "1:35"  "20:35" "20:40" "20:45"
[15] "20:50" "20:55" "21:00" "21:05" "21:10" "21:15" "21:20" "21:25"
Run Code Online (Sandbox Code Playgroud)

几乎所有我的例子都让我工作了.
我如何得到它以使其适用于数字"5"......"45" "50" "55"

在这里发现了这个副本,但这不使用gsub

regex r

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

数据表智能搜索 v 无智能搜索 v 正则表达式

给定这个数据表示例,可以选择正则表达式、smartserach 或两者都没有(正则表达式、smartserach),智能搜索会做什么?

例如,在“名称”列下:
输入Ai搜索会返回 4 个条目,无论是否勾选了智能搜索。谁能提供一个例子,我可以看到智能搜索勾选与否的区别?

例如,在“名称”列下:
键入^[A]将返回 3 个已勾选正则表达式的条目。在此示例中,勾选智能搜索与否似乎没有什么区别。同样,任何人都可以提供一个示例,让我可以看到勾选了智能搜索与勾选了正则表达式的差异吗?


编辑1

链接是可能有帮助的文档

这里看来,启用智能搜索和正则表达式可能不太好:Note that to perform a smart search, DataTables uses regular expressions, so if enable regular expressions using the second parameter to this method, you will likely want to disable smart searching as the two regular expressions might otherwise conflict and cause unexpected results.

datatables

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

在d3中是否有等效的jquery .empty()?

在jQuery中,我可以使用以下内容清除/清空div:

$("#graph").empty()
Run Code Online (Sandbox Code Playgroud)

所以上面的命令会清除/清空下面的div,如果它里面有任何标签<div id="graph"></div>.

是否有相同的方法来做到这一点是d3?

在这看到我的PLUNKER

这里有Plunker代码片段:

<div id="mylist">hello test1</div>


<div id="graph">hello test2</div>

<script>        
        $("#graph").empty() // comment out to not empty the div
</script>        
Run Code Online (Sandbox Code Playgroud)

EDIT1

PLUNKER供我参考,基于以下答案.

jquery d3.js

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

VBA - 删除另一个工作表中的行

Function DeleteRows()

Dim wb As Workbook
Set wb = Workbooks(ThisWorkbook.Name)

Debug.Print wb.Name

Dim wsName As String
Dim ws As Worksheet
wsName = "SheetX"
Set ws = wb.Worksheets(wsName)

Debug.Print ws.Name


With ws
        Debug.Print "ws.name = " & ws.Name
        Rows("3:31").Select

        Selection.Delete Shift:=xlUp

End With
End Function
Run Code Online (Sandbox Code Playgroud)

我有这个函数 DeleteRows,它从工作表“SheetX”中删除 3:31 的行。

这仅在“SheetX”是显示在屏幕上的工作表时有效。

I want it to work when another sheet, lets say "SheetY", in the workbook is displayed. How can I do this?

One way would be to: 1-activate "SheetY" 2-delete the rows …

excel vba rows

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

将数组转换为对象数组

如何用键转动此数组

> dd
[ 'DeviceName',
  'counter1',
  'counter2',
  'counter3',
  'counter4' ]
Run Code Online (Sandbox Code Playgroud)

用对象进入这个对象数组

[
    { data: 'DeviceName' },
    { data: 'counter1' },
    { data: 'counter2' },
    { data: 'counter3' },
    { data: 'counter4' }
]
Run Code Online (Sandbox Code Playgroud)

我试过这个函数,但问题是数据键在它们中都是一样的.

有没有解决的办法?

 newdd=function toObject(arr) {
      var rv = {};
      var a =[];
        for (var i = 0; i < arr.length; ++i) {
        rv["data"] = arr[i];
        a.push(rv);
        }
      return a;
    }
Run Code Online (Sandbox Code Playgroud)

这给了我:

> newdd(dd)
[ { data: 'counter4' },
  { data: 'counter4' },
  { data: 'counter4' },
  { …
Run Code Online (Sandbox Code Playgroud)

javascript arrays object

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

如果没有传入参数,我如何分配默认值 + python

我该怎么写,letter = sys.argv[2] or 'a'以便如果没有传入的参数a将被分配给字母。 所以基本上我希望默认值lettera除非传入某些东西。如果要传入某些东西,我希望将其分配给letter

这是我的简单程序:

$ cat loop_count.py
import sys

def count(word,letter):
        for char in word:
                if char == letter:
                        count = count + 1
        return count
                                # WHAT I WANT
word = sys.argv[1] or 'banana'  # if sys.argv[1] has a value assign it to word, else assign 'banana' to word
letter = sys.argv[2] or 'a'     # if sys.argv[2] has a value assign it to letter, else assign 'a' …
Run Code Online (Sandbox Code Playgroud)

python

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

打印出以字母表中每个字母开头的文件中第一次出现的单词

我有一个带有形容词A - Z列表的文件

如何打印以A开头的第一个单词,然后是以B开头的第一个单词...一直到Z?
我认为grep可能就是这样.但对其他人开放,awk,python ......其他.

一些样本输出:

$ cat adjectives.txt | head
Adamant: unyielding; a very hard substance
Adroit: clever, resourceful
Amatory: sexual
Animistic: quality of recurrence or reversion to earlier form
Antic: clownish, frolicsome
Arcadian: serene
Baleful: deadly, foreboding
Bellicose: quarrelsome (its synonym belligerent can also be a noun)
Bilious: unpleasant, peevish
Boorish: crude, insensitive

$ cat adjectives.txt | grep '^[ABCDE]' | head
Adamant: unyielding; a very hard substance
Adroit: clever, resourceful
Amatory: sexual
Animistic: quality of recurrence or …
Run Code Online (Sandbox Code Playgroud)

python bash awk grep

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

Jscript + jquery +一个基本区别的例子

我是学习JS的新手,想要更好地理解这个概念,所以请提前道歉,因为我对这个问题的无知或简单.我基本上试图建立一个简单的问答游戏来学习JavaScript.

基本上我试图理解这两个版本之间的区别:

JavaScript示例

Jquery的例子

基本上我试图理解这两行的区别:

JavaScript的

document.getElementById("question").innerHTML = "<b>Question " + questionIndex +"</b>: " + allQuestions[0][questionIndex-1];
Run Code Online (Sandbox Code Playgroud)

JQuery的

$("#question").text("<b>Question " + questionIndex +"</b>: " + allQuestions[0][questionIndex-1]) 
Run Code Online (Sandbox Code Playgroud)

JavaScript版本将以粗体显示"问题X:",但不会在Jquery版本中显示.为什么?如何使Jquery版本的粗体部分工作?或者关于此的一般性建议?

TKS

javascript jquery button

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

在命令行中运行php脚本+非常基本

现在也许这是一个完全新手/愚蠢的问题,道歉,但......

我有以下文件:

$ cat helloWorldScript.php
/*here I want to be able to run this in the command line
witht the command pho scriptname.php.
*/
<?php  Print "Hello, World!\n"; ?>
Run Code Online (Sandbox Code Playgroud)

现在我可以按如下方式运行脚本:

$ php helloWorldScript.php
/*here I want to be able to run this in the command line
witht the command pho scriptname.php.
*/
Hello, World!
Run Code Online (Sandbox Code Playgroud)

或者像-f参数一样 -f <file> Parse and execute <file>.

$ php -f helloWorldScript.php
/*here I want to be able to run this in the command line
witht the …
Run Code Online (Sandbox Code Playgroud)

php

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

使用 find 命令格式化时间戳

此命令用于-printf '%Tc %p\n'提供上次修改文件的日期。

$ find ./ -daystart -mtime -3 -type f  ! -mtime -1  -printf '%Tc %p\n'
Tue 08 Mar 2016 12:25:01 NZDT ./compareKPIs-log
Tue 08 Mar 2016 18:04:58 NZDT ./backup_public_html_20160308.tgz
Tue 08 Mar 2016 18:04:58 NZDT ./log-file
Tue 08 Mar 2016 12:25:01 NZDT ./compareKPIs-error
Mon 07 Mar 2016 18:05:02 NZDT ./backup_public_html_20160307.tgz
Run Code Online (Sandbox Code Playgroud)

我想要做的是将日期格式控制为YYYY-mm-dd. 我该怎么做呢?(如果需要,也可以在此处添加 hh:mm:ss)

例如-printf '%TY %p\n'会给我年份%TY

$ find ./ -daystart -mtime -3 -type f  ! -mtime -1  -printf '%TY %p\n' …
Run Code Online (Sandbox Code Playgroud)

linux printf date find

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

如何用文件名中的今天创建一个文件

指令1:

$ touch test"date"
Run Code Online (Sandbox Code Playgroud)

指令2:

$ date +"%F"
2018-01-16
Run Code Online (Sandbox Code Playgroud)

我希望能够运行命令以便test_2018-01-16创建文件。如何或可以结合以上两个命令来执行此操作?

$ touch test_"date"
Run Code Online (Sandbox Code Playgroud)

EDIT1-答案

ks

这些命令

touch fred-`date +%F`
touch "test-$(date +%F)"
touch "test2_$(date +"%F %T")"
Run Code Online (Sandbox Code Playgroud)

分别提取以下文件

fred-2018-01-16
test-2018-01-16
test2_2018-01-16 11:51:53
Run Code Online (Sandbox Code Playgroud)

linux bash

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

标签 统计

linux ×3

awk ×2

bash ×2

javascript ×2

jquery ×2

python ×2

arrays ×1

button ×1

cmd ×1

d3.js ×1

datatables ×1

date ×1

excel ×1

find ×1

grep ×1

object ×1

php ×1

printf ×1

r ×1

regex ×1

rows ×1

tr ×1

vba ×1

windows ×1