Hot answers tagged

12

I think it's probably because you're explicitly asking grep to search recursively from /var, and /var/run does not match a SUBDIRECTORY under /var. See grep man page, which states: --exclude-dir=glob [..] skip any subdirectory whose base name matches glob. [..] FIX Therefore, to fix your command, change the exclude pattern, i.e.: sudo grep -IR --...


3

To select any line containing gold from source.txt and replace the first occurrence of green with red: $ sed -n '/gold/{s/green/red/; p}' source.txt gold red white black blue To save that in a file: sed -n '/gold/{s/green/red/; p}' source.txt >pol.txt How it works -n tells sed not to print lines unless we explicitly ask it to. /gold/ selects ...


2

Try: awk -F "|" '{ a[$5]+=1+length($0) } END{for (name in a) print name,a[name]}' trace.log Example Let's consider this test file: $ cat trace.log 1|2|3|4|jerry|6 a|b|c|d|phil|f 1|2|3|4|jerry|6 The original command produces this output: $ awk -F "|" '{ print $5 }' trace.log | sort | uniq | xargs -l sh -c 'echo -n $0 && grep "$0" trace.log | ...


2

Questions 1 and 3 are related and can be answered at a time. As per the grep man page (emphasis mine): --exclude-dir=DIR Exclude directories matching the pattern DIR from recursive searches. So basically what you specify with that option is a pattern and not a directory itself, meaning /var/www/sometext* or even /var/www/sometext/* will expand and ...


1

grep -l "gold" source.txt will output source.txt if the file contains the word gold xargs sed 's/green/red/' will run sed 's/green/red/' source.txt and the final redirect saves the result in your output. If I understand your intent correctly, you want the following command: sed -n '/gold/s/green/red/p' source.txt > pol.txt The /gold/ selects lines ...


1

Probably you want case insensitivity and whitespace tolerance, and grep will terminate if it doesn't find any instances of the desired file pattern in the current directory. It needs to know where to start, as it were, and no files matched produces no starting path. If there is at least one file of the desired extension, then you can use egrep -ir. find ...



Only top voted, non community-wiki answers of a minimum length are eligible