How do I remove newlines from a text file?

后端 未结 19 2417
遇见更好的自我
遇见更好的自我 2020-11-29 17:34

I have the following data, and I need to put it all into one line.

I have this:

22791

;

14336

;

22821

;

34653

;

21491

;

25522

;

33238

;
         


        
19条回答
  •  北荒
    北荒 (楼主)
    2020-11-29 18:19

    I usually get this usecase when I'm copying a code snippet from a file and I want to paste it into a console without adding unnecessary new lines, I ended up doing a bash alias
    ( i called it oneline if you are curious )

    xsel -b -o | tr -d '\n' | tr -s ' ' | xsel -b -i
    
    • xsel -b -o reads my clipboard

    • tr -d '\n' removes new lines

    • tr -s ' ' removes recurring spaces

    • xsel -b -i pushes this back to my clipboard

    after that I would paste the new contents of the clipboard into oneline in a console or whatever.

提交回复
热议问题