Miscellaneous Shell Notes (3)
The Journey of Learning Shell, Part 3
07/26/23 Corrected typos
07/27/23 Added command
BC
Short for Basic Calculator, this is a calculator provided in accordance with the POSIX standard and available on Unix-based systems.
Key features include:
-
Stack-based structure
-
Support for Reverse Polish notation (RPN)
echo '2 + 3' | dc
dc <<< '2 3 + p'
TR
A command that enables character conversion, deletion, and compression. It is typically used in conjunction with additional processes via a pipeline.
*tr [문자열1] [문자열2]
: Takes two strings of equal length and replaces the corresponding characters in string 1 with the characters at the same indices in string 2.
-
-c: Replaces all characters not present in the second set with the last character of that set.
-
-s: Removes all repeating sequences and replaces them with a specified character.
-
-d: Removes the specified character.
-
-t: Trims both strings to match their lengths before executing the command.
SED (
)
A command that supports various editing functions. It operates primarily on a buffer, so the original file remains unaffected until modifications are applied.
Command Options
-
Patterns are expressed in the form /[pattern]/.
-
Add -g to process all matching patterns.
-
Use commas (,) to specify ranges.
-
p: Prints all lines and prints an additional line for each pattern match
- Add the -n option: Excludes default output; prints only lines matching the pattern
-
d: Deletes the pattern
-
s: Replaces the pattern
-
e: Edit mode
*n;
: Next line
-
y: Y-confirmation
-
i: Insert
-
c: Change
-
a: Append
# 약간의 응용
sed -n 'n; p': 짝수 줄 출력
sed -n 'p; n': 홀수 줄 출력
WC
Word Count
-
-l: Check the number of lines in the file
-
-c: Check the number of bytes in the file
-
-m: Check the number of characters in the file
-
-w: Check the number of words in the file
댓글 작성
게시글에 대한 의견을 남겨 주세요.