linux merge multiline files

文件内容
cat  test .txt 
reportType
 
orderId
 
sid
hospitalName
customerName
customerSex
customerPhone
customerId
orderNum
doctorName
recordName
 
symptom
docSymptom
diagnosis
checkResult
medicine
surgery
prevTreatment
curMedHistory
prevMedHistory
bodyCheck

Merge multiple lines

1
2
tr  -s  "\n"  " "  test .txt ; echo
reportType orderId sid hospitalName customerName customerSex customerPhone customerId orderNum doctorName recordName symptom docSymptom diagnosis checkResult medicine surgery prevTreatment curMedHistory prevMedHistory bodyCheck medicalOrders check imgs docImages channelId brokerId brokerAvator reportSelf status createdAt updatedAt isDeleted version lock

Method 1 is added after merging,

1
2
echo  ` tr  -s  "\n"  " "  test .txt; echo ` |  sed  "s/ /,/g"
reportType,orderId,sid,hospitalName,customerName,customerSex,customerPhone,customerId,orderNum,doctorName,recordName,symptom,docSymptom,diagnosis,checkResult,medicine,surgery,prevTreatment,curMedHistory,prevMedHistory,bodyCheck,medicalOrders,check,imgs,docImages,channelId,brokerId,brokerAvator,reportSelf,status,createdAt,updatedAt,isDeleted,version,lock

Method Two

1
echo  ` sed  "/^$/d"  test .txt |  sed  "s@\(.*\)@\1,@g" `

First delete the blank line of the file, add it, and then print it to a line

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326796687&siteId=291194637