CLI (Command-Line Interface) 3

Garam·2023년 8월 1일
0

The Odin Project

목록 보기
3/14

https://swcarpentry.github.io/shell-novice/04-pipefilter.html



$ wc file.pdb
>> 20 156 1158 file.pdb

wc = word count
lines, words, characters (from left to right)
wc -l only shows the number of lines
wc -m characters
wc -w words



Capturing output from commands


$ wc -l *.pdb > lengths.txt

Redirects the command’s output to a file

$ sort -n lengths.txt > sorted-lengths.txt

  1. 숫자 기준으로 정렬한 후 sorted-lenghts.txt에 저장 (-n 없으면 알파벳 순서)
  2. Shows the first line of the file (ex: -n 20 would get the first 20)

❗️ $ sort -n file.txt > file.txt
Don’t redirect to the same file. It might give you incorrect results and/or delete the content.

sort -r = reverse order


echo hello

hello 그대로 프린트

$ echo hello > testfile01.txt
$ echo hello >> testfile02.txt

  1. The file gets overwritten each time we run the command
  2. It also writes ‘hello’ to the file, but it appends the string to the file if it already exists

$ head -n 3 sorted-lengths.txt
$ tail -n 2 sorted-lengths.txt

  1. The first 3 lines of the file (세 줄 전부)
  2. The last 2 lines of the file




Passing output to another command


$ sort -n lengths.txt | head -n 1

| (pipe) = Use the output of the left as the input to the right
This has removed the need for the sorted-lengths.txt file.


$ wc -l *.pdb | sort -n | head -n 1

Multiple pipes can be used.




0개의 댓글