Sed+awk realizes the combination of multiple lines of characters in a single file into a single line

Text to be treated as follows:
[the root @ DB-Read1 ~] # CAT 5.txt
12021012910058460004
12021012810086009004
82021013010077270001
82021013010122917003
12021013010153074001
1HH202101310991143
12021013110169858002
12021013110169858003
3021012910165310001
12021013110105288003
12021013110105288004
2,021,013,110,154,350,004

The result is:

'12021012910058460004' '12021012810086009004' '82021013010077270001' '82021013010122917003' '12021013010153074001' '1HH202101310991143' '12021013110169858002' '12021013110169858003' '3021012910165310001' '12021013110105288003' '12021013110105288004' '2021013110154350004'
放到一行展示出来,要求单引号直间有空格

The implementation commands are as follows:

[root@db-read1 ~]#  cat 5.txt |awk '{print " " $0}'|sed -e "s/ /\'/g"|sed -e "s/\'/'/g" |paste -d " " -s -
'12021012910058460004' '12021012810086009004' '82021013010077270001' '82021013010122917003' '12021013010153074001' '1HH202101310991143' '12021013110169858002' '12021013110169858003' '3021012910165310001' '12021013110105288003' '12021013110105288004' '2021013110154350004'

[root@db-read1 ~]#  cat 5.txt |awk '{print " " $0}'|sed -e "s/ /\'/g"|sed -e "s/\'/'/g" |tr -s "\n" " ";echo
'12021012910058460004' '12021012810086009004' '82021013010077270001' '82021013010122917003' '12021013010153074001' '1HH202101310991143' '12021013110169858002' '12021013110169858003' '3021012910165310001' '12021013110105288003' '12021013110105288004' '2021013110154350004'

Reference article:
https://blog.51cto.com/bad51men/1149973

Guess you like

Origin blog.51cto.com/wujianwei/2621172
Recommended