ITeye博客

linux 合并多行文件

ronin47 · 2016-01-10 10:37 · system · 操作系统 · Markdown

文件内容

cat test.txt

reportType

 

orderId

 

sid

hospitalName

customerName

customerSex

customerPhone

customerId

orderNum

doctorName

recordName

 

symptom

docSymptom

diagnosis

checkResult

medicine

surgery

prevTreatment

curMedHistory

prevMedHistory

bodyCheck

多行合并

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

方法一合并之后添加,

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

方法二

1

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

先删除文件的空行,在添加,然后打印到一行

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。