grep

How to grep a term from S3 and output object name

谁说我不能喝 提交于 2021-02-20 04:49:07
问题 I need to grep a term over thousands of files in S3, and list those file names in some output file. I'm quite new using cli, so I've been testing both on my local, and in a small subset in s3. So far I've got this: aws s3 cp s3://mybucket/path/to/file.csv - | grep -iln searchterm > output.txt The problem with this is with the hyphen. Since I'm copying over to standard output, the -l switch in grep returns (standard input) instead of file.csv My desired output is file.csv Eventually, I'll need

Does zgrep unzip a file before searching? [closed]

此生再无相见时 提交于 2021-02-19 09:40:06
问题 Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . Improve this question Does zgrep unzip a gzip file and make a temporary copy before searching or does it search directly on the compressed file? 回答1: This source of zgrep uncompresses the file with zcat and pipes the result to grep . So, no, it does not use a temporary file, but yes,

How to get lines from the last match to the end of file?

邮差的信 提交于 2021-02-19 06:39:10
问题 Need to print lines after the last match to the end of file. The number of matches could be anything and not definite. I have some text as shown below. MARKER aaa bbb ccc MARKER ddd eee fff MARKER ggg hhh iii MARKER jjj kkk lll Output desired is jjj kkk lll Do I use awk with RS and FS to get the desired output? 回答1: You can actually do it with awk (gawk) without using any pipe. $ awk -v RS='(^|\n)MARKER\n' 'END{printf "%s", $0}' file jjj kkk lll Explanations: You define your record separator

GREP by result of awk

有些话、适合烂在心里 提交于 2021-02-19 06:22:44
问题 Output of awk '{print $4}' is b05808aa-c6ad-4d30-a334-198ff5726f7c 59996d37-9008-4b3b-ab22-340955cb6019 2b41f358-ff6d-418c-a0d3-ac7151c03b78 7ac4995c-ff2c-4717-a2ac-e6870a5670f0 I need to grep file st.log by these records. Something like awk '{print $4}' |xargs -i grep -w "pattern from awk" st.log I dont know how to pass pattern correctly? 回答1: What about awk '{print $4}' | grep -F -f - st.log Credits to Eric Renouf, who noticed that -f - can be used for standard input instead -f <(cat) ,

GREP by result of awk

China☆狼群 提交于 2021-02-19 06:22:42
问题 Output of awk '{print $4}' is b05808aa-c6ad-4d30-a334-198ff5726f7c 59996d37-9008-4b3b-ab22-340955cb6019 2b41f358-ff6d-418c-a0d3-ac7151c03b78 7ac4995c-ff2c-4717-a2ac-e6870a5670f0 I need to grep file st.log by these records. Something like awk '{print $4}' |xargs -i grep -w "pattern from awk" st.log I dont know how to pass pattern correctly? 回答1: What about awk '{print $4}' | grep -F -f - st.log Credits to Eric Renouf, who noticed that -f - can be used for standard input instead -f <(cat) ,

quickest way to select/copy lines containing string from huge txt.gz file

喜你入骨 提交于 2021-02-19 04:21:49
问题 So I have the following sed one liner: sed -e '/^S|/d' -e '/^T|/d' -e '/^#D=/d' -e '/^##/d' -e 's/H|/,H|/g' -e 's/Q|/,,Q|/g' -e '1 i\,,,' sample_1.txt > sample_2.txt I have many lines that start with either: S| T| #D= ## H| Q| The idea is to not copy the lines starting with one of the first fours and to replace H| (at the beginning of lines) by ,H| and Q| (at the beginning of lines) by ,,Q| But now I would need to: use the fastest way possible (internet suggests (m)awk is faster than sed)

quickest way to select/copy lines containing string from huge txt.gz file

随声附和 提交于 2021-02-19 04:21:25
问题 So I have the following sed one liner: sed -e '/^S|/d' -e '/^T|/d' -e '/^#D=/d' -e '/^##/d' -e 's/H|/,H|/g' -e 's/Q|/,,Q|/g' -e '1 i\,,,' sample_1.txt > sample_2.txt I have many lines that start with either: S| T| #D= ## H| Q| The idea is to not copy the lines starting with one of the first fours and to replace H| (at the beginning of lines) by ,H| and Q| (at the beginning of lines) by ,,Q| But now I would need to: use the fastest way possible (internet suggests (m)awk is faster than sed)

How to print the next word after a found pattern with grep,sed and awk?

北城余情 提交于 2021-02-18 22:26:28
问题 for example, suppose I have logfile.txt which contains "Here is a sample text file" My pattern is "sample" How can I get the word next to sample in my logfile.txt. 回答1: Here is one way to do it with awk: $ awk '{for(i=1;i<=NF;i++)if($i=="sample")print $(i+1)}' file text Explained: $ awk '{ for(i=1;i<=NF;i++) # process every word if($i=="sample") # if word is sample print $(i+1) # print the next }' file and sed: $ sed -n 's/.* sample \([^ ]*\).*/\1/p' file text ie. after sample next space

Parsing HTML on the command line; How to capture text in <strong></strong>?

假如想象 提交于 2021-02-18 06:47:06
问题 I'm trying to grab data from HTML output that looks like this: <strong>Target1NoSpaces</strong><span class="creator"> .... <strong>Target2 With Spaces</strong><span class="creator"> .... I'm using a pipe train to whittle down the data to the targets I'm trying to hit. Here's my approach so far: grep "/strong" output.html | awk '{print $1}' Grep on "/strong" to get the lines with the targets; that works fine. Pipe to 'awk '{print $1}'. That works in case #1 when the target has no spaces, but

How to grep an exact string with slash in it?

谁说胖子不能爱 提交于 2021-02-16 18:24:12
问题 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