bash cat multiple files content in to single string without newlines

前端 未结 3 755
庸人自扰
庸人自扰 2021-01-02 00:25

i got some files with name start as eg_. and only each contains one single line

eg_01.txt: @china:129.00

eg_02.txt @uk:219.98

eg_03.txt @USA:341.90

相关标签:
3条回答
  • 2021-01-02 01:17

    You could always pipe it to tr

    tr "\n" " "
    

    That removes all newlines on stdin and replaces them with spaces

    EDIT: as suggested by Bart Sas, you could also remove newlines with tr -d

    tr -d "\n"
    

    (note: just specifying an empty string to tr for the second argument won't do)

    0 讨论(0)
  • 2021-01-02 01:19

    In Perl, you'd do it like this:

    perl -pe'chomp' eg*.txt
    

    The -p says "loop through the input file and do whatever code is specified by the -e switch. The chomp in Perl says "Remove any trailing newlines."

    0 讨论(0)
  • 2021-01-02 01:20

    Using only one command

    url=$(awk '{printf "%s",$0}' eg*)
    
    0 讨论(0)
提交回复
热议问题