# Tag Info

6

If the IP address is always the second field of that file, you can use awk or cut to extract it. awk '{print $2}' abd or cut -d' ' -f2 abd If you need to iterate through the IP addresses, the usual for or while loops can be used. For example: for ip in$(cut -d' ' -f2 abd) ; do ... ; done or awk '{print $2}' abd | while read ip ; do ... ; done ... 6 . is a regular expression metacharacter which matches any single character. \ is also a regular expression metacharacter which can be used to escape any metacharacter so that it will be literally matched. and so . matches any character, but \. matches only .. printf %c900983\\n a . | grep -n ".900983" 1:a900983 2:.900983 ...because the . regular ... 5 GNU grep buffers output but GNU awk does not. And even if you were not using GNU awk and were using some other variant it would likely still be line-buffered if you were printing to a terminal and so would flush output for each occurring \newline, but your grep writes to a pipe and so would block-buffer anyway. If you have a GNU grep you can use grep ... 5 Sounds like a job for tee: build | tee /some/file ami_name=$(do_something_to /some/file) deploy "$ami_name" 4 For the first one: grep -oP 'IBM/WebSphere/\K[0-9]\.[0-9]' file For the second one: grep -oP 'IBM/WebSphere/\K[0-9]\.[0-9].*java ' file -P activates Perl regular expressions -o prints only the matching part IBM/WebSphere/\K the beginning of the part until \K which empties the matching variable, so this wil not be part of what is printed [0-9]\.[0-9] a ... 4 grep does not necessarily need input from a pipe, so you could do grep -vE '90\.192\.142\.138|PIX|Intrusion' cisco.log-20151103.log Capital E switches on regular expression mode and dots need to be escaped in this case. 4 From the uniq manpage: DESCRIPTION Discard all but one of successive identical lines from INPUT (or standard input), writing to OUTPUT (or standard output). Here the critical word is "successive". It doesn't search for duplicates at any point in the stream, only those that immediately follow. Sorting forces all duplicates to be next to each other, ... 4 Assuming no spaces in your file names (and that your heart isn't set on using find), this should do the trick: for file in *.ft1; do if grep -q 'special'${file}; then ls -l ${file%.ft1}.log 2> /dev/null fi done It uses bash string manipulation to pull .ft1 off of the end. I could use${file/ft1/log}, but that would also match any ...

4

Your issue is that you need a shell to interpret the *.log glob. So you need -execdir to invoke a shell. The following snippet will also address your "same name stem" requirement find . -name "*.ft1" -exec grep -l "special" {} \; \ -execdir bash -c 'x=$1; x=${x%.txt}; ls "$x".log' bash {} \; 4 This one is easy: grep -E "199[5-9]" does the job. It is easy, because the intended number range matches a character code range. For a more complicated example, e.g., 1998-2003, you will have to split the range appropriately: grep -E "199[8-9]|200[0-3]" 3 Your awk example is doing the entire regex search in one pass. For each line of input, if the first, second, and third regex is found, the line will be printed, and you'll see the output essentially immediately (upon processing of the matching line). Your grep example is using 3 different invocations of grep (one for each regex) to do the same thing, but ... 3 The grep pipeline could not output anything until the final grep for string4 matched something, and it only gets its input after the previous pipe buffer fills up. See related questions How big is the pipe buffer? and Turn off buffering in pipe . Depending on the frequency of the strings in your input, you could see a difference in runtimes by putting the ... 3 Your regular expression doesn't work because . is not a word character. Grep only considers a-z, A-Z, 0-9 and _ to be word characters. In any case, this is really not the right way to do this. First of all, parsing ls is very fragile and almost never a good idea. Here are some other ways of listing directories whose name starts with a .: find . -type d ... 3 Looking at your snippet, it looks like you've got XML delimited by 'number='. So extract with split: #!/usr/bin/env perl use strict; use warnings; use Data::Dumper; local$/; my @xml_chunks = split ( /\d+\=/, <> ); print Dumper \@xml_chunks; Of course, you should probably note - your XML ... isn't. The declaration isn't valid. I'm going to assume ...

3

The original question would be solved by cat test.xml | tr "<" "\n" | sed -n '/taga>./p' | sed 's/taga>//' the second, current question would be solved with cat test.xml | sed 's/[0-9][0-9][0-9][0-9]=/\n/g' it looks for an occurence of four numbers followed by an = sign, so if you might have those kinds of characters in other places in the real string ...

3

Use the -F options to make grep treat pattern as fixed string: grep -F 'abc.def.ghi' <file And also note that you don't need to invoke egrep.

3

This is wide known operation in awk — collect array from key-file then use the array to operate with second file values awk ' FNR==NR{ A[$2] = A[$2] " " $1 next }$1 in A{ for(i=1;i<=split(A[$1], B);i++) print$1 B[i] } ' file2 file1 Or a little bit shorter: awk ' FNR==NR{ ...

3

ps -Aocomm= | sed -ne'/java$/s|.*/$$[0-9]\.$$|\1|p' It looks like ps output there, but, if so, it is probably a mistake to include the arguments to the commands for which you search. This is especially true if you're grepping the results because the search pattern for .*java.* or what-have-you will then likely match for the grep command you run. ... 3 You're using csh, which sees the * and tries to expand it as a shell glob and fails. That is, it's csh saying "No match" here, not grep. Unlike Bourne family shells, csh won't pass an unexpandable glob pattern on to the command, so you must quote it to get csh to release it to grep. I recommend single quotes here since you aren't trying to interpolate a ... 3 A very crude solution with find , awk, and bash. Basic idea, find all files with ft1 extension, give them as list of command line args to grep, which outputs a list of files with do contain "special" string, then pipe that output to awk that will string out ft1 extension and replace it with "log" extension. Finally give it to bash, which will check if a log ... 3 Using grep -r and awk grep -rl 'special' *.ft1 | awk '{sub(/\.ft1$/,"");system("sh -c \"[ -f "$0".log ] && echo \\\"["$0".log\\\"] exists for ["$0".ft1]\"")}' or with the output of ls grep -rl 'special' *.ft1 | awk '{sub(/\.ft1$/,"");system("sh -c \"[ -f "$0".log ] && ls "$0".log \"")}' Example % grep -rl 'special' *.ft1 | awk ...

3

This is happening because the a* and b* are not quoted and, therefore, are expanded by the shell before being passed to grep. For example, consider this directory: $ls afile.txt bfile.txt regex.txt If I try to run grep a* regex.txt, the a* will become afile.txt and that is what will be given as a search pattern to grep. We can use bash's debugging ... 3 With GNU find, you can test each directory: for i in "$dir"/*/ do test -n "$(find "$i" -type f -regex '.*/test[^/]*' -print -quit)" \ && echo "$i" done This searches each directory for a file beginning test and prints the directory if it's found. A couple of things to note: I'm ignoring subdirectories that begin with .; if they need ... 3 Change the following line: grepFails=$(egrep "\\def$myVar\>" myFile) With: grepFails=$(egrep "\\\\def\\$myVar\>" myFile) The problem was that you were not escaping the \ properly in the subshell. To understand, try running eval echo "\\\\". You will notice that the output is \ because of the double evaluation. 3 Using just grep, you can do: grep -E '[aeiouAEIOU]{3}' This finds three vowels in a row. To disallow Roman numerals, and only valid Roman numerals (i.e. VI, VII, IX, XIV, are all valid, but VIX is not) you need a much more complicated setup and probably shouldn't be using just grep. 3 You could use awk, exit on line 3 (the END rule is still executed) and exit 1 in the END block if no. of lines is not 2 e.g. with zsh: print -rl -- *(.e_'awk "NR==3{exit}END{if(NR!=2){exit 1}}"$REPLY'_) will list two-line files in the current directory; replace print -rl with mv and add the destination if you want to move them. With other shells: for ...

3

if your filenames are fairly sane, and you can delimit on both : and a newline, then: grep -m3 '' ./* ./*/* | cut -d: -f1 | uniq -c | grep -v '^ *[13] ' ^that command will list all not-dot files in the current directory and in all immediate child directories which contain only two lines. You don't really need to worry about sorting for uniq, because ...

3

I don't know what homework checker you are referring to but the issue here is probably that you are not counting lines with x, youi are counting occurences of x. The -o flag makes grep print only the matched portion of a line, if there are many xs on the same line, it will print each of them separately: $echo "xxx" | grep -o x x x x So, you don't want -o ... 2 For efficiency, grep and many other commands use buffered I/O, that is, they read large blocks of data at once (rather than, say, one character at a time), and do not output data until a certain amount has been amassed (rather than, say, writing a line at a time or a character at a time) But, when a program's input is from a terminal (such as your serial ... 2 You'll have to extract the ID substring from the file names. One way to do that is via parameter expansion e.g.${var:offset:length} so in your case var is filename, offset is 5 (order) and length is ${#f}-9 (that is, total length${#f} minus the combined length of order and .log which is 9 characters): for f in order*.log ...

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