grep

remove all lines in a file containing a string from another file

╄→гoц情女王★ 提交于 2021-02-07 04:31:05
问题 I'd like to remove all the lines of a file based on matching a string from another file. This is what I have used but it only deletes some: grep -vFf to_delete.csv inputfile.csv > output.csv Here are sample lines from my input file (inputfile.csv): Ata,Aqu,Ama3,Abe,0.053475,0.025,0.1,0.11275,0.1,0.15,0.83377 Ata135,Aru2,Aba301,A29,0.055525,0.025,0.1,0.082825,0.075,0.125 Ata135,Atb,Aca,Am54,0.14695,0.1,0.2,0.05255,0.025,0.075,0.8005, Adc,Aru7,Ama301,Agr84,0.002075,0,0.025,0.240075,0.2,0. My

grep output into array

梦想的初衷 提交于 2021-02-06 09:01:52
问题 Guys How can I make this work `find /xyz/abc/music/ |grep def` I don't want to store the array in any temporary variable. How can we directly operate on this array. so to get the 1st element of that array echo ${$(`find /xyz/abc/music/ |grep def`)[0]} Please help me How I can achieve this 回答1: If you just need the first element (or rather line), you can use head : `find /xyz/abc/music/ |grep def | head -n 1` If you need access to arbitrary elements, you can store the array first, and then

grep output into array

跟風遠走 提交于 2021-02-06 09:01:30
问题 Guys How can I make this work `find /xyz/abc/music/ |grep def` I don't want to store the array in any temporary variable. How can we directly operate on this array. so to get the 1st element of that array echo ${$(`find /xyz/abc/music/ |grep def`)[0]} Please help me How I can achieve this 回答1: If you just need the first element (or rather line), you can use head : `find /xyz/abc/music/ |grep def | head -n 1` If you need access to arbitrary elements, you can store the array first, and then

grep output into array

心不动则不痛 提交于 2021-02-06 09:01:02
问题 Guys How can I make this work `find /xyz/abc/music/ |grep def` I don't want to store the array in any temporary variable. How can we directly operate on this array. so to get the 1st element of that array echo ${$(`find /xyz/abc/music/ |grep def`)[0]} Please help me How I can achieve this 回答1: If you just need the first element (or rather line), you can use head : `find /xyz/abc/music/ |grep def | head -n 1` If you need access to arbitrary elements, you can store the array first, and then

Delete a list of files with find and grep

我是研究僧i 提交于 2021-02-05 12:48:14
问题 I want to delete all files which have names containing a specific word, e.g. "car". So far, I came up with this: find|grep car How do I pass the output to rm? 回答1: find . -name '*car*' -exec rm -f {} \; or pass the output of your pipeline to xargs : find | grep car | xargs rm -f Note that these are very blunt tools, and you are likely to remove files that you did not intend to remove. Also, no effort is made here to deal with files that contain characters such as whitespace (including

Finding a string in docker logs of container

你离开我真会死。 提交于 2021-02-05 12:42:22
问题 What is the best way to find a specific string in the logs of a docker container? Let's say I want to see all requests, that are made in the "nginx" docker image that came from a ip starting with "127." grep wont work as expected on docker logs command: docker logs nginx | grep "127." It prints all logs, but does not filter the result! 回答1: this can happen if the container is logging to stderr, piping works only for stdout, so try: docker logs nginx 2>&1 | grep "127." 回答2: As vim fan I prefer

Finding a string in docker logs of container

帅比萌擦擦* 提交于 2021-02-05 12:41:02
问题 What is the best way to find a specific string in the logs of a docker container? Let's say I want to see all requests, that are made in the "nginx" docker image that came from a ip starting with "127." grep wont work as expected on docker logs command: docker logs nginx | grep "127." It prints all logs, but does not filter the result! 回答1: this can happen if the container is logging to stderr, piping works only for stdout, so try: docker logs nginx 2>&1 | grep "127." 回答2: As vim fan I prefer

Using regex in Grep for Windows command line

柔情痞子 提交于 2021-02-05 10:10:22
问题 I want to capture all lines which contain exactly 3 fields, where a field is any string (possibly empty) followed by a | (and there may be some final text at the end of the line). I managed to build a regex which seems to do exactly what I want ^(?:[^\|]*\|){3}[^\|]*$ and when I try it on 101regex it seems to work just fine. However, I am having problems to run this regex on the Windows command line via grep and I guess it has something to do with the proper escaping. I tried grep -E '^^(?:[^

Using regex in Grep for Windows command line

梦想的初衷 提交于 2021-02-05 10:02:50
问题 I want to capture all lines which contain exactly 3 fields, where a field is any string (possibly empty) followed by a | (and there may be some final text at the end of the line). I managed to build a regex which seems to do exactly what I want ^(?:[^\|]*\|){3}[^\|]*$ and when I try it on 101regex it seems to work just fine. However, I am having problems to run this regex on the Windows command line via grep and I guess it has something to do with the proper escaping. I tried grep -E '^^(?:[^

grep lines that start with a specific string

你。 提交于 2021-02-05 00:59:27
问题 I want to find all the lines in a file that start with a specific string. The problem is, I don't know what's in the string beforehand. The value is stored in a variable. The naïve solution would be the following: grep "^${my_string}" file.txt; Because if the Bash variable my_string contains ANY regular expression special characters, grep will cry, and everyone will have a bad day. You don't want to make grep cry, do you? 回答1: You should use awk instead of grep for non-regex search using