文件内容
cat test .txt
reportType
orderId
sid
hospitalName
customerName
customerSex
customerPhone
customerId
orderNum
doctorName
recordName
symptom
docSymptom
diagnosis
checkResult
medicine
surgery
prevTreatment
curMedHistory
prevMedHistory
bodyCheck
多行合并
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
方法一合并之后添加,
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
方法二
echo ` sed "/^$/d" test .txt | sed "s@\(.*\)@\1,@g" `
先删除文件的空行,在添加,然后打印到一行