Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 years ago.
Improve this question
What command would you give to list all English-language words that are exactly 5 characters long and that begin with an upper or lower-case vowel (‘a’, ‘e’, ‘i’, ‘o’, ‘u’, or ‘y’), have a lower-case ‘t’ in the middle position, and end with a lower-case ‘s’?
The remaining letters could be any character that occurs in English words, including but not limited to upper and lower-case alphabetics, numbers, hyphens, etc.
You had it almost!
grep ^[AaEeIiOoUuYy].t.s$ /usr/share/dict/words
Since I prefer complex pipelines to complex regular expressions, here's my take:
cat /usr/share/dict/words \
| grep -E -x ".{5}" \
| grep '^[aeiouyAEIOUY]' \
| grep '..t.s'
(Useless use of cat added for readability).
On my Ubuntu it produces this output:
Art's
Estes
Oates
Oct's
Yates
act's
altos
ant's
antes
antis
art's
autos
iotas
oat's
oaths
out's
(You can replace .{5} with \w{5} or with [a-zA-Z0-9-]{5} or whatever you like).
I've actually written a similar script to chea.. I mean, help me with crosswords.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 12 months ago.
Improve this question
what does rm ** do in linux.
started learning linux and stuck here.
I tried reading but couldnt understand or didn get the answer
* is a wildcard. Wildcard characters are used to define the pattern for searching or matching text on string data in the bash shell.
The shell interprets certain characters in filenames and for other purposes as well. It passes the interpreted version to commands. For example, the most commonly used special character is asterisk, * , meaning "zero or more characters". When you type a command like ls a* , the shell finds all filenames in the current directory starting with a and passes them to the ls command.
Since rm is to remove, rm ** will delete all the files from where you run the command.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
I got the following line
2020-10-17 14:55:39,586 INFO [http-bio-exec-60] [] [D88E13F571A51598613FAA078A215326.server.host.com.:9991] [some.package.Class] TEST_STRING - RSI: 506B48ECADC4BE0CEBF7C7D33D036B67.server.host.com.:9991
I do grep "D88E13F571A51598613FAA078A215326" and got the line above. Is there a way to run a command after grep to check if D88E13F571A51598613FAA078A215326 and 506B48ECADC4BE0CEBF7C7D33D036B67 are equal?
Thanks.
This will work if you already know the first pattern:
PATTERN=D88E13F571A51598613FAA078A215326
grep "\[$PATTERN.*RSI: $PATTERN" input_file
I got the following line, that's not a good way to start here:
Your line contains quite some information, and as mentioned in the comments, you might parse it using Perl or awk or any other tool, but I would advise otherwise: how do you get this line (I guess it's an output of some process)? You might ask the author of that other process to alter the output in such a way that it's easier for you do parse it and do the comparison you're aiming for.
Pipe grep output into this Perl one-liner, which splits the line on non-word characters and prints it if fields 13 and 23 are identical as strings:
echo '2020-10-17 14:55:39,586 INFO [http-bio-exec-60] [] [D88E13F571A51598613FAA078A215326.server.host.com.:9991] [some.package.Class] TEST_STRING - RSI: 506B48ECADC4BE0CEBF7C7D33D036B67.server.host.com.:9991' | \
grep 'D88E13F571A51598613FAA078A215326' | \
perl -F'/\W+/' -lane 'print if $F[12] eq $F[22];'
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 1 year ago.
Improve this question
I want to make a command where I list that directories which are contains only two letters.
How can I do it?
? is a wildcard for one character. So, the following should work:
ls -d ??/
The -d prevents ls from listing the contents of the directories, the final / excludes files.
ls -F | grep -o "^.\{2\}/$"
ls -F lists content by file system object type
| grep -o filters out anything that doesn't match the regex expression ^.\{2\}/$ which basically says 'match only folders with 2 characters in their name'
ls */ | awk 'length($0) < 3'
Note that this does not match hidden directories. choroba's answer is better, because it is usually a bad idea to parse the output of ls, but I like this for its readability.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I try
ls */ | grep "\.txt$"
to find all .txt file in the subdirectory but it seems that it can't work well all the time.
The pattern you want can easily be matched with a single glob:
ls */*.txt
The ls isn't necessary; it just demonstrates that it works. You can also use
echo */*.txt
printf '%s\n' */*.txt
files=( */*.txt )
for f in */*.txt; do ....
The pattern itself (*/*.txt) will expand to the list of the matching files; what you can do with that list is fairly broad.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
I am relatively new to linux environment. My doubt is this:
I run a lot of commands of various types , so when ever i want to rerun a old one i have to look through the entire history. is there any bash command that displays just the commands that begin with a particular combination of characters( my case here is i just want a list of all the ./ eg: ./ifv_script , ./run_regression i've run from the terminal)
Three methods:
You can grep your current history, e.g.:
$ history | grep ifv
You can also recall commands from the history by typing ControlR and then type a few characters from the command.
Finally you can grep your saved history file for older invocations from previous sessions, e.g.:
$ grep ifv ~/.bash_history
Just press Ctrl+R, and you will enter into reverse-i-search mode.
Now you can type a few characters that appear anywhere in the command and bash will start finding matches.
Final approach (bash only):
history | grep term