태터데스크 관리자

도움말
닫기
적용하기   첫페이지 만들기

태터데스크 메시지

저장하였습니다.

달력

122019  이전 다음

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  •  
  •  
  •  
  •  

1.     패턴으로 문자열 자르기

1.1. 패턴에서 6번째  추출(/etc/passwd에서  디렉토리 추출)

# grep coriahn /etc/passwd | awk -F : '{print $6}'

Awk 이용해서 : 구분자로 6번째 필드를 출력


1.2. 패턴에서 마지막  추출(패스에서 마지막 패스 추출)

# echo ${PATH##*:}

: 구분자로 마지막값 출력 ## 의미는 일단 미지수


1.3. 패턴에서 마지막  잘라내기(파일명에서 확장자 제거)

# path=back.sh

# echo ${path%.*}

back

“.”을 구분자로 하여 마지막 패턴을 삭제하는듯


2.     추가사항은 나중에..

 

BASH: Split a string without ‘cut’ or ‘awk’

For a little test script I’m writing I needed to split a line on a ‘;’ but preservere the “s and ‘s, something that echo doesn’t like to do. Digging deeper into the bash docs I see that there are some handy string handling functions.

#!/bin/bash
line=’this “is” a command;this “is” a pattern’
COMMAND=${line%;*}
PATTERN=${line#*;}
echo $COMMAND
echo $PATTERN

And the output would be:

this “is” a command
this “is” a pattern


http://www.antonolsen.com/2006/04/10/bash-split-a-string-without-cut-or-awk/


Posted by coriahn coriahn

댓글을 달아 주세요