[태그:] sed

  • xargs로 여러 줄을 한줄로 줄이기

    https://stackoverflow.com/questions/15758814/turning-multiple-lines-into-one-line-with-comma-separated-perl-sed-awk

    file

    aaa
    bbb
    ccc
    ddd

    xargs

    cat file | xargs

    result

    aaa bbb ccc ddd 

    xargs improoved

    cat file | xargs | sed -e 's/ /,/g'

    result

    aaa,bbb,ccc,ddd 

    변태 같은 명령어라고 표현해야 하나..

  • SED로 같은 행에 단어 추가

    https://stackoverflow.com/questions/35252285/insert-text-with-sed-on-the-same-line-that-pattern-search

    sed로 정규 표현을 찾아, 같은 라인의 마지막에 삽입하는 명령.

    sed 's/\blocalhost\b/& 192.168.25.50/' file
        \b: a zero-width word boundary
        &: refer to that portion of the pattern space which matched

    이걸 모르면 ( )와 \1로 개 지랄을 해야 되는데..