Back (Current repo: scraps)

random scraps and notes that are useful to me
To clone this repository:
git clone https://git.viktor1993.net/scraps.git
Log | Download | Files | Refs

flatten_newlines.sh (517B)


function flatten_newlines() {

    FILE="$1"

    if [ -z $FILE ]; then
        echo "A file is needed"
        return 1
    fi

    sed ':m;$!{N;s/\n/ /;bm;}' "$FILE"

    #Explanation for the random wanderer looking in here:
    #:m     ->         define label m
    #$!{}   ->         If current line is not the last line
    #N      ->         append next line to pattern space, aka join the lines
    #s\n/ / ->         replace the newline between them with a space
    #b m    ->         loop back to label m
}