grep

Need help matching a mattern using grep/egrep in bash scripting

旧街凉风 提交于 2020-01-11 11:13:48
问题 I am trying to match all characters of given string but those characters should match in the order as given to the bash script. while [[ $# -gt 0 ]]; do case $1 in -i) arg=$2 egrep "*[$arg]*" words.txt shift ;; esac shift done $ sh match_the_pattern.sh -i aei words.txt Should return words like abstentious adventitious sacrilegiousness If you notice, first a is matched then e and then i , all of them are in order. Plus, the whole word is matched and filtered. 回答1: Change this: arg=$2 egrep "*[

Grep for String and open at the corresponding line

别等时光非礼了梦想. 提交于 2020-01-11 10:03:33
问题 I'm having several occurrences of a specific string over several files in several lines obtained with grep . $ grep -rn --include="*.cpp" mystring lib/mlib/actionbuttonrule.cpp:300: mystring Foobar... lib/mlib/actionbuttonrule.cpp:314: other mystring lib/mlib/item.cpp:3025: /* mystring**/ lib/mlib/item.cpp:3082: mystring Foobar... lib/mlib/item.cpp:3095: Foo mystring bar I'd like to open these files sequencially on the corresponding lines. I tried to do it with vim , but so far no success

Grep for String and open at the corresponding line

为君一笑 提交于 2020-01-11 10:03:13
问题 I'm having several occurrences of a specific string over several files in several lines obtained with grep . $ grep -rn --include="*.cpp" mystring lib/mlib/actionbuttonrule.cpp:300: mystring Foobar... lib/mlib/actionbuttonrule.cpp:314: other mystring lib/mlib/item.cpp:3025: /* mystring**/ lib/mlib/item.cpp:3082: mystring Foobar... lib/mlib/item.cpp:3095: Foo mystring bar I'd like to open these files sequencially on the corresponding lines. I tried to do it with vim , but so far no success

Grep for String and open at the corresponding line

核能气质少年 提交于 2020-01-11 10:02:07
问题 I'm having several occurrences of a specific string over several files in several lines obtained with grep . $ grep -rn --include="*.cpp" mystring lib/mlib/actionbuttonrule.cpp:300: mystring Foobar... lib/mlib/actionbuttonrule.cpp:314: other mystring lib/mlib/item.cpp:3025: /* mystring**/ lib/mlib/item.cpp:3082: mystring Foobar... lib/mlib/item.cpp:3095: Foo mystring bar I'd like to open these files sequencially on the corresponding lines. I tried to do it with vim , but so far no success

How to redirect grep output to a variable?

怎甘沉沦 提交于 2020-01-11 09:30:11
问题 I have some pipe. For example, I have this pipe: user@user:~$ cal | head -1 | grep -oP "[A-Za-z]+" For this pipe I get this result: September I want to store this result to a variable. I write the following commands: user@user:~$ cal | head -1 | month=$(grep -oP "[A-Za-z]+") | echo $month And I get the blank string. What is the problem? 回答1: month=$(cal | head -1 | grep -oP "[A-Za-z]+") or month=$(date +%B) 来源: https://stackoverflow.com/questions/25710640/how-to-redirect-grep-output-to-a

Convert Rows into Columns by matching string in R

时间秒杀一切 提交于 2020-01-11 09:28:38
问题 I have number of rows in a list like ' [1,] "Home" [2,] "A" [3,] "B" [4,] "C" [5,] "Home" [6,] "D" [7,] "E" [8,] "Home" [9,] "F" [10,] "G" [11,] "H" [12,] "I" these rows are coming dynamically...after "Home" there can be two,three,four,five or more subcategories....so binding is not working... I have more than 5000 rows and "Home" is common in the start for every subcategories.. I Want it to look like this. [,1] [,2] [,3] [,4] [,5] [1,] "Home" "A" "B" "C" [2,] "Home" "D" "E" [3,] "Home" "F"

grep with continuous pipe does not work

吃可爱长大的小学妹 提交于 2020-01-11 09:23:09
问题 (maybe it is the "tcpflow" problem) I write a script to monitoring http traffic, and I install tcpflow , then grep it works (and you should make a http request, for example curl www.163.com ) sudo tcpflow -p -c -i eth0 port 80 2>/dev/null | grep '^Host: ' it outputs like this (continuously) Host: config.getsync.com Host: i.stack.imgur.com Host: www.gravatar.com Host: www.gravatar.com but I can't continue to use pipe does not work (nothing output) sudo tcpflow -p -c -i eth0 port 80 2>/dev/null

grep with continuous pipe does not work

你。 提交于 2020-01-11 09:23:06
问题 (maybe it is the "tcpflow" problem) I write a script to monitoring http traffic, and I install tcpflow , then grep it works (and you should make a http request, for example curl www.163.com ) sudo tcpflow -p -c -i eth0 port 80 2>/dev/null | grep '^Host: ' it outputs like this (continuously) Host: config.getsync.com Host: i.stack.imgur.com Host: www.gravatar.com Host: www.gravatar.com but I can't continue to use pipe does not work (nothing output) sudo tcpflow -p -c -i eth0 port 80 2>/dev/null

Is it possible to use egrep to match numbers within a range?

僤鯓⒐⒋嵵緔 提交于 2020-01-11 07:45:10
问题 Is there a way to grep / egrep between two sets of numbers? egrep "SomeText [19999-22000]" /some/file.txt It's not returning the values. I expect: SomeText 19999 ffuuu SomeText 20001 ffuuu SomeText 21000 ffuuu 回答1: regex is not the right tool for math stuff (although sometimes it can do), in your case, try the awk: awk '$2>=19999 && $2<=22000' file 回答2: You can use the range function , with awk awk '$2=="19999",$2=="22000"' file SomeText 19999 ffuuu SomeText 20001 ffuuu SomeText 21000 ffuuu

Linux系统巡检脚本

孤街浪徒 提交于 2020-01-10 18:01:20
#!/bin/bash # auth:Bertram # created Time : 2019-12-26 # func:sys info check # sys:centos6.x/7.x ------------------------------------------------------------------------------------------------------------------------------------- [ $(id -u) -ne 0 ] && echo "请用root用户执行此脚本!" && exit 1 sysversion=$(rpm -q centos-release|cut -d- -f3) line="-------------------------------------------------" [ -d logs ] || mkdir logs #sys_check_file="logs/$(ip a show dev eth0|grep -w inet|awk '{print $2}'|awk -F '/' '{print $1}')-`date +%Y%m%d`.txt" sys_check_file="logs/$(ifconfig |awk 'NR==2{print $2}')-`date +%Y