Engineer/Linux

[bash] cut

mjune.kim 2021. 3. 4. 21:44

리눅스 커멘드 cut 을 이용해 문자열을 자르거나 특정 위치의 문자만을 추출해 낼 수 있습니다.

예를 들어 아래와 같이 문자열의 두번째 문자만을 추출할 수도 있습니다.

$!/bin/bash

data="abcde"
echo $data | cut -c 2

결과

또는 문자열들을 저장하고 있는 파일로 부터 문자를 추출할 수도 있습니다.

File: data.txt
abcd
abcd efgh

--
#!/bin/bash
cut -c 2,7 data.txt

결과값

더보기

b

bf

쉘에서 문자열을 변경하고나 특정 문자 / 문자열을 추출할 때 유용할 듯 하네요.

www.geeksforgeeks.org/cut-command-linux-examples/

 

cut command in Linux with examples - GeeksforGeeks

A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.

www.geeksforgeeks.org