The original problem is https://leetcode.com/problems/word-frequency/. In fact, counting word frequency is a typical application of bash. For example, Example 16-12 in this bash guide.
..................
The original problem is https://leetcode.com/problems/word-frequency/. In fact, counting word frequency is a typical application of bash. For example, Example 16-12 in this bash guide.
..................
The original problem is https://leetcode.com/problems/tenth-line/. This is a basic application of bash: just get the 10th line from a file. Many methods can solve this simple question.
..................
The original problem is https://leetcode.com/problems/transpose-file/.
This question is difficult for one who is not familiar with the bash tools, such as awk
.
The first time I tried with a column-by-column handling with sed
:
..................
The original problem is https://leetcode.com/problems/valid-phone-numbers/. The basic problem here to match lines of telephone numbers in form of 123-456-789 (123) 456-789
..................
Using regular expressions(REs) is just like using REs in other common languages (C#, java, php, python...). REs in bash has two syntaxes, basic
and extended
, which are defined in IEEE POSIX standard. The basic syntax is the default mode in bash.
Commonly used metacharacters used in bash are
[ ]
bracket expression. Used to match a selection of characters.
.
dot sign matches any single character.
*, +, ?
matches a preceding item zero or more times, one or more times, zero or one time, resp.
^, $
matches the empty string in the start, or the end of a line.
..................