grep

Remove columns that contain a specific word

[亡魂溺海] 提交于 2020-02-03 09:56:24
问题 I have a data set that has 313 columns, ~52000 rows of information. I need to remove each column that contains the word "PERMISSIONS". I've tried grep and dplyr but I can't seem to get it to work. I've read the file in, testSet <- read.csv("/Users/.../data.csv") Other examples show how to remove columns by name but I don't know how to handle wildcards. Not quite sure where to go from here. 回答1: From what I could understand from the question, the OP has a data frame like this: df <- read.table

grep two files (a.txt, b.txt) - how many lines in b.txt starts (or ends) with the words from a.txt - output: 2 files with the results

ぐ巨炮叔叔 提交于 2020-02-02 10:19:25
问题 I know I ask too much, but maybe you can help with this problem too. a.txt contains words, b.txt contains strings. I would like to know how many string from b.txt ends with the words from a.txt Example: a.txt apple peach potato b.txt greenapple bigapple rottenapple pinkpeach xxlpotatoxxx Output 3 apple greenapple bigapple rottenapple 1 peach pinkpeach I would like to have a solution with grep, since it is way more faster than awk. Can you guys please help me? 回答1: Here is an awk solution awk

grep two files (a.txt, b.txt) - how many lines in b.txt starts (or ends) with the words from a.txt - output: 2 files with the results

半腔热情 提交于 2020-02-02 10:19:09
问题 I know I ask too much, but maybe you can help with this problem too. a.txt contains words, b.txt contains strings. I would like to know how many string from b.txt ends with the words from a.txt Example: a.txt apple peach potato b.txt greenapple bigapple rottenapple pinkpeach xxlpotatoxxx Output 3 apple greenapple bigapple rottenapple 1 peach pinkpeach I would like to have a solution with grep, since it is way more faster than awk. Can you guys please help me? 回答1: Here is an awk solution awk

查找命令之find 与 grep

痞子三分冷 提交于 2020-01-31 17:40:58
一、Find(查找文件或目录) 1.在/var/lib目录下查找所有文件其所有者是root用户的文件。 find /var/lib -user root 2.查找家目录其所有者不是linux用户,并用长格式显示(如ls –l 的显示结果)。 把前面的结果当成是后面的命令中的 { } 的输入,然后执行并输出到屏幕 sudo find ~ ! -user linux -exec ls -l { } \ ; 2.1、查找文件然后复制到/tmp目录下 find /var/lib -user root -exec cp -r { } /tmp \ ; 3.查找某一目录下名字是*.txt的文件 find /home -name "*.txt" -type f 3.1、查找某一目录下名字是*.txt的目录 find /home -name "*.txt" -type d 4.当前目录查找30天以前的文件 find . -name "*.txt" -type f mtime +30 4.14.当前目录查找1天以内的文件 find . -name "*.txt" -type f mtime -1 5.查找大于5M的文件 M是大写,k是小写,才能识别 find . -name "*.txt" -type f mtime -1 -size 5M 6.查找权限是644的文件 文件默认权限666,目录777

Linux shell命令总结大全

核能气质少年 提交于 2020-01-31 15:05:58
前言 Linux shell命令应该算是非常入门的东西,但是实际上在使用的时候,会遇到各种各样的问题,前几天我在我们的项目上需要做一个功能,根据进程名字杀死这个进程,下面是过程 1、我们正常需要的操作是 $ps |grep xxx $kill -9 xx 2、kill命令是常用的,但是用killall命令会更快 $killall -9 xxx 3、令我困扰的是我用的那个没有killall然后我做了下面的操作 $adb shell ps |grep speech |awk '{print $2}' > 1.txt $cat 1.txt |xargs -n1 adb shell kill -9 我用这个的原因是用一条指令重定向总是各种问题,正常情况下用这条就可以了 $adb shell ps |grep speech |awk '{print $2}'|xargs -n1 kill -9 正文 关机/重启 关机(必须用root用户) shutdown -h now ## 立刻关机 shutdown -h +10 ## 10分钟以后关机 shutdown -h 12:00:00 ##12点整的时候关机 halt # 等于立刻关机 重启 shutdown -r now reboot # 等于立刻重启 echo root@ubuntu:~# a="hello,world" root

linux中的查找相关命令

对着背影说爱祢 提交于 2020-01-31 14:37:30
1. find Linux find命令用来在指定目录下查找文件。任何位于参数之前的字符串都将被视为欲查找的目录名。如果使用该命令时,不设置任何参数,则find命令将在当前目录下查找子目录与文件。并且将查找到的子目录和文件全部进行显示。 find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression] '-H'表示只跟随命令行中指定的符号连接, '-L'表示跟随所有的符号连接, '-P'是默认的选项,表示不跟随符号连接。 '-D' debugoptions. 打印诊断信息 '-Olevel' Enables query optimisation. 允许查询优化 -name filename #查找名为filename的文件 -perm #按执行权限来查找 -user username #按文件属主来查找 -group groupname #按组来查找 -mtime -n +n #按文件更改时间来查找文件,-n指n天以内,+n指n天以前 -atime -n +n #按文件访问时间来查GIN: 0px"> -ctime -n +n #按文件创建时间来查找文件,-n指n天以内,+n指n天以前 -nogroup #查无有效属组的文件,即文件的属组在/etc

使用Haproxy+lua代理Mongodb副本集

喜夏-厌秋 提交于 2020-01-31 02:39:43
一般情况下,使用mongo客户端,或者其他语言的mongo客户端驱动程序连接mongodb副本集的时候,只需要指定副本集名称,就可以实现当mongodb副本集主备切换时的高可用目标。 但是总有一些特殊的场合,连接到副本集的客户端与副本集所在的网络是隔离的,只能通过副本集所在网络的代理访问副本集,比如说,mongodb副本集被部署到k8s上,当k8s集群外的客户端想访问副本集时,只能通过代理进行访问,如通过haproxy访问副本集。 那么问题来了,客户端只知道代理的ip地址或者url,当副本集主备切换时,客户端通过副本集名称是不会连接到副本集的主实例的,这里提供一个haproxy+lua代理mongo副本集的方式可以解决这个问题。 关于haproxy和lua的使用方法和说明,请参考如下链接: https://www.arpalert.org/haproxy-lua.html 首先,创建一个简易的mongodb副本集(同一主机端口不同,没有用户名密码等安全设置): # 通过以下shell创建一个简易的mongodb副本集 ​ # 杀掉已存在的mongo实例 ps -ef | grep mongod | grep -v grep | awk '{print $2}' | xargs kill -9 ; ​ # 清理并创建目录供副本集使用 rm -rf /data/47017/* &&

grep out load average from uptime

*爱你&永不变心* 提交于 2020-01-30 07:44:05
问题 what I want to do is take the command uptime, and get the load averages $ uptime 07:01:30 up 20:29, 2 users, load average: 0.32, 0.39, 0.54 I have a feeling this is something I can do with awk, but I am not quite sure how. pls assist. 回答1: You can use a regex with backreferences: i.e. find any sequence of characters (.*) but only at a point directly after average: uptime | grep -oP '(?<=average:).*' 回答2: You can use grep uptime | grep -o 'load.*' Also you can extract the three load average

三剑客之grep

◇◆丶佛笑我妖孽 提交于 2020-01-29 23:52:30
grep -i:不区分大小写 –color:高亮显示 -v:被匹配到的不显示 -o:只显示匹配到字符串 元字符: *:任意长度的任意字符 ?:任意单个字符 【】:匹配范围内的 【^】:匹配范围外的 正则表达式:REGular EXPression(REGEXP) 正则表达式默认情况下工作在贪婪模式下 正则表达式的元字符: . :匹配任意单个字符 *:表示其前边的字符任意次(0或多次) a, b,ab,aab,acb,adb,amnb a*b 不可,可,可,可,不可,不可,不可, a出现0次或者多次,接下来就是b,所以后边三个不可以。(a出现了任意次后跟了个b) a.*b 不 不 可 可 可 可 可 任意长度的任意字符(以a开始以b结束,中间可以是任意长度的任意字符) . *:任意长度的任意字符 来源: CSDN 作者: 梁欣伟 链接: https://blog.csdn.net/qq_42508901/article/details/104109617

grep -f file to print in order as a file

有些话、适合烂在心里 提交于 2020-01-29 12:13:14
问题 I have a a requirement to grep patterns from a file but need them in order. $ cat patt.grep name1 name2 $ grep -f patt.grep myfile.log name2:some xxxxxxxxxx name1:some xxxxxxxxxx I am getting the output as name2 was found first it was printed then name1 is found it is also printed. But my requirement is to get the name1 first as per the order of patt.grep file. I am expecting the output as name1:some xxxxxxxxxx name2:some xxxxxxxxxx 回答1: You can pipe patt.grep to xargs , which will pass the