grep

How to grep an exact string with slash in it?

两盒软妹~` 提交于 2021-02-16 18:24:05
问题 I'm running macOS. There are the following strings: /superman /superman1 /superman/batman /superman2/batman /superman/wonderwoman /superman3/wonderwoman /batman/superman /batman/superman1 /wonderwoman/superman /wonderwoman/superman2 I want to grep only the bolded words. I figured doing grep -wr 'superman/|/superman' would yield all of them, but it only yields /superman. Any idea how to go about this? 回答1: You may use grep -E '(^|/)superman($|/)' file See the online demo: s="/superman

How to delete rows from a csv file based on a list values from another file?

佐手、 提交于 2021-02-13 12:16:43
问题 I have two files: candidates.csv : id,value 1,123 4,1 2,5 50,5 blacklist.csv : 1 2 5 3 10 I'd like to remove all rows from candidates.csv in which the first column ( id ) has a value contained in blacklist.csv . id is always numeric. In this case I'd like my output to look like this: id,value 4,1 50,5 So far, my script for identifying the duplicate lines looks like this: cat candidates.csv | cut -d \, -f 1 | grep -f blacklist.csv -w This gives me the output 1 2 Now I somehow need to pipe this

How to delete rows from a csv file based on a list values from another file?

百般思念 提交于 2021-02-13 12:15:52
问题 I have two files: candidates.csv : id,value 1,123 4,1 2,5 50,5 blacklist.csv : 1 2 5 3 10 I'd like to remove all rows from candidates.csv in which the first column ( id ) has a value contained in blacklist.csv . id is always numeric. In this case I'd like my output to look like this: id,value 4,1 50,5 So far, my script for identifying the duplicate lines looks like this: cat candidates.csv | cut -d \, -f 1 | grep -f blacklist.csv -w This gives me the output 1 2 Now I somehow need to pipe this

egrep and grep difference with dollar

﹥>﹥吖頭↗ 提交于 2021-02-11 17:24:34
问题 I'm having touble understanding the different behaviors of grep end egrep when using \$ in a pattern. To be more specific: grep "\$this->db" file # works egrep "\$this->db" file # does not work egrep "\\$this->db" file # works Can some one tell me why or link some explanation? Thank you very much. 回答1: The backslash is being eaten by the shell's escape processing, so in the first two cases the regexp is just $this->db . The difference is that grep treats a $ that isn't at the end of the

bash grep 'random matching' string

余生颓废 提交于 2021-02-11 15:19:32
问题 Is there a way to grab a 'random matching' string via bash from a text file? I am currently grabbing a download link via bash, curl & grep from a online text file. Example: DOWNLOADSTRING="$(curl -o - "http://example.com/folder/downloadlinks.txt" | grep "$VARIABLE")" from online text file which contains http://alphaserver.com/files/apple.zip http://alphaserver.com/files/banana.zip where $VARIABLE is something the user selected. Works great, but i wanted to add some mirrors to the text file.

Grep for lines not beginning with “//”

a 夏天 提交于 2021-02-11 12:11:54
问题 I'm trying but failing to write a regex to grep for lines that do not begin with "//" (i.e. C++-style comments). I'm aware of the "grep -v" option, but I am trying to learn how to pull this off with regex alone. I've searched and found various answers on grepping for lines that don't begin with a character, and even one on how to grep for lines that don't begin with a string, but I'm unable to adapt those answers to my case, and I don't understand what my error is. > cat bar.txt hello //world

Grepl group of strings and count frequency of all using R

一个人想着一个人 提交于 2021-02-11 12:08:56
问题 I have a column of 50k rows of tweets named text from a csv file (the tweets consists of sentences, phrases etc). I'm trying to count frequency of several words in that column. Is there an easier way to do it vs what I'm doing below? # Reading my file tweets <- read.csv('coffee.csv', header=TRUE) # Doing a grepl per word (This is hard because I need to look for many words one by one) coffee <- grepl("coffee", text$tweets, ignore.case=TRUE) mugs <- grepl("mugs", text$tweets, ignore.case=TRUE)

Grepl group of strings and count frequency of all using R

一世执手 提交于 2021-02-11 12:08:23
问题 I have a column of 50k rows of tweets named text from a csv file (the tweets consists of sentences, phrases etc). I'm trying to count frequency of several words in that column. Is there an easier way to do it vs what I'm doing below? # Reading my file tweets <- read.csv('coffee.csv', header=TRUE) # Doing a grepl per word (This is hard because I need to look for many words one by one) coffee <- grepl("coffee", text$tweets, ignore.case=TRUE) mugs <- grepl("mugs", text$tweets, ignore.case=TRUE)

Grep for lines not beginning with “//”

こ雲淡風輕ζ 提交于 2021-02-11 12:04:38
问题 I'm trying but failing to write a regex to grep for lines that do not begin with "//" (i.e. C++-style comments). I'm aware of the "grep -v" option, but I am trying to learn how to pull this off with regex alone. I've searched and found various answers on grepping for lines that don't begin with a character, and even one on how to grep for lines that don't begin with a string, but I'm unable to adapt those answers to my case, and I don't understand what my error is. > cat bar.txt hello //world

Merging word counts with Bash and Unix

本秂侑毒 提交于 2021-02-10 19:52:28
问题 I made a Bash script that extracts words from a text file with grep and sed and then sorts them with sort and counts the repetitions with wc , then sort again by frequency. The example output looks like this: 12 the 7 code 7 with 7 add 5 quite 3 do 3 well 1 quick 1 can 1 pick 1 easy Now I'd like to merge all words with the same frequency into one line, like this: 12 the 7 code with add 5 quite 3 do well 1 quick can pick easy Is there any way to do that with Bash and standard Unix toolset? Or