오지랖의 반대말은 무엇일까?

무관심?

무책임?

무지?

'Life > A sentense of the day' 카테고리의 다른 글

듣기  (0) 2018.03.29
병원  (0) 2018.03.27
  (0) 2018.01.10
틀린 사람  (0) 2018.01.07
엉킴  (0) 2017.12.24

Bash script 에서 case 는 아래와 같은 형태를 가진다.

case variable in

case1)

statement1;;

case2)

statement2;;

*)

statement_default;;

esac


'Programming > Bash Script' 카테고리의 다른 글

Bash script argument parsing with getopts  (0) 2020.01.23
Bash script for statement  (0) 2018.05.21
Bash Script Variable Split by Space  (0) 2018.02.04
Bash Script Echo  (0) 2018.02.04
Bash Script String  (0) 2017.07.04

Linux 사용시 파일 내부의 특정 표현을 수정하고자 하는 경우 sed 명령어를 활용할 수 있다.


sed 의 기본적인 형태는 아래와 같다.

sed <options> <address> <commands> <filename>

<options>

-n : suppress automatic printing (sed는 Matching 되는 Line 외에도 모든 Line 을 기본적으로 printing 하는데, line number 를 출력하고자 하는 경우(command =) 또는, Matching 되는 line 만 출력하고자 하는 경우(command /p)에는 -n option을 활용하면 된다.)

<address>

number : Match only the line number

/regular_expression/ : Match lines matching the regular_expression

addr1,addr2 : Match lines from addr1 to addr 2

addr,+N : Match addr and the following N lines

addr,~N : Match lines from addr to N*addr

<commands>

= : print the line number

/p : print the line

s/regular_expression/replacement : replace 


다만, 순전히 내 기준에서 가장 많이 사용하는 sed의 형태는 아래와 같다.

sed s/<regular_expression>/<replace>/g <file>

여기서 /g는 vim에서 replace 할 때의 /g 와 마찬가지로, 여러 개가 매칭 되는 경우 여러번 실행하도록 하는 옵션


sed 는 <file> 로 부터 <regular_expression> 을 찾아 <replace> 로 치환하여, 표준 출력을 해준다.

이는 vim 에서 replace 하는 것과 비슷하다.

결과물이 표준 출력 되기 때문에, 아래와 같이 > 또는 >> 를 이용해 파일에 써줄 수 있다.

다만, 여기서 파일이 이름이 같은 경우 아무것도 써지지 않는다는 점을 유의하자.

sed s/<regular_expression/<replace>/g <input_file> > <output_file>


아래는 예시

sed s/^$//g test.txt > test.txt.tmp

mv test.txt.tmp test.txt

(test.txt 파일로 부터 공백인 행을 없애 test.txt.tmp 파일에 출력한다.)


'Programming > Linux' 카테고리의 다른 글

Linux HDD mount  (0) 2018.04.06
HandBrakeCLI  (0) 2018.04.06
Linux find  (0) 2018.02.04
Ubuntu sources.list generation  (0) 2017.09.06
Ubuntu Redshift  (0) 2017.07.02

Bash Script 사용할 때,

shell 명령어에 대한 return을 받은 variable 이 space로 구분된 string 이라면,

아래와 같이 명령어를 배열처럼 구분하여 사용할 수 있다.

string_ex="I am your Father"

str_array=($string_ex)

echo ${str_array[0]} #I

echo ${str_array[1]} #am

echo ${str_array[2]} #you

echo ${str_array[3]} #Father


'Programming > Bash Script' 카테고리의 다른 글

Bash script for statement  (0) 2018.05.21
Bash Script case statement  (0) 2018.02.06
Bash Script Echo  (0) 2018.02.04
Bash Script String  (0) 2017.07.04
Bash Script If statement  (0) 2017.07.04

Linux system 에서 파일을 찾고자 할 떄,

find 함수를 사용하면 찾을 수 있다.


기본적인 사용법은 아래와 같다.

$ find <directory> -name <finding_file_name>


옵션으로 아래와 같이 사용 할 수 있다.

-type f : 파일

-type d : 폴더(directory)

-maxdepth 1 : find 는 기본적으로 하위 디렉토리까지 전부 검사 한다. maxdepth는 하위 몇 디렉토리 까지 검사할 것인지를 설정한다.

-and : 여러개의 조건에 대해 찾고자 할때 -and 옵션과 함께 조건을 추가할 수 있다.

-and ! : 해당 조건이 거짓인 경우에 대해 찾고자 할 때, -and ! 을 사용하면 된다.

-iname : 파일 이름의 대소문자를 고려하지 않고 검색한다.


아래는 예시

$ find . -type f -name 'abc*' -and ! -name 'abc'

(현재 디렉토리로 부터 abc로 시작하는 이름을 가진 파일 중에 파일 이름이 abc는 아닌 것을 찾는다.


xargs와 함께 사용하면, 

디렉토리에서 원하는 파일을 복사/삭제 하기 수월하다

예시

$ find . -type f -name 'abc*' -and ! -name 'abc' | xargs rm -f

(현재 디렉토리로 부터 abc로 시작하는 이름을 가진 파일 중에 파일 이름이 abc는 아닌 것을 찾아 삭제한다.

'Programming > Linux' 카테고리의 다른 글

HandBrakeCLI  (0) 2018.04.06
Linux sed  (0) 2018.02.05
Ubuntu sources.list generation  (0) 2017.09.06
Ubuntu Redshift  (0) 2017.07.02
Linux timezone  (0) 2017.06.20

Bash Script echo 사용 시 줄바꿈을 하고 싶지 않다면,

-n

$ echo -n "hello "

$ echo "world"

hello world

'Programming > Bash Script' 카테고리의 다른 글

Bash Script case statement  (0) 2018.02.06
Bash Script Variable Split by Space  (0) 2018.02.04
Bash Script String  (0) 2017.07.04
Bash Script If statement  (0) 2017.07.04
Bash script argument  (0) 2017.06.20

한가할 때 잠을 자는 것은

번아웃이거나,

열정이 없는 것이다.


'Life > A sentense of the day' 카테고리의 다른 글

병원  (0) 2018.03.27
오지랖의 반대말  (0) 2018.03.05
틀린 사람  (0) 2018.01.07
엉킴  (0) 2017.12.24
이상함  (0) 2017.10.23

내가 틀린 짓을 하고 있는데,

누군가 내 편을 든다면,

그 사람은 고맙지만 틀린 사람이다

'Life > A sentense of the day' 카테고리의 다른 글

오지랖의 반대말  (0) 2018.03.05
  (0) 2018.01.10
엉킴  (0) 2017.12.24
이상함  (0) 2017.10.23
사실  (0) 2017.10.13

누구의 잘못도 아닌 상황으로 인해, 마음이 엉킬 때가 있다.


KBS 드라마 고백부부 중에서

'Life > A sentense of the day' 카테고리의 다른 글

  (0) 2018.01.10
틀린 사람  (0) 2018.01.07
이상함  (0) 2017.10.23
사실  (0) 2017.10.13
인사  (0) 2017.08.17

Python 으로 tab/공백 으로 구분 된 파일 parsing 하여 array로 만들기


#input file open

file = open(file_name, "r")


#output array of table

table_data = []


#for every row

for line in file:

#split by white spaces(column)

tmp_array = line.strip().split(" ")


#remove NO value element

while tmp_array.count(""):

tmp_array.remove("")


table_data.append(tmp_array)


'Programming > Python' 카테고리의 다른 글

Python Apt-get  (1) 2018.08.03

+ Recent posts