Bash - how to put each line within quotation

后端 未结 7 1288
既然无缘
既然无缘 2020-12-30 21:14

I want to put each line within quotation marks, such as:

abcdefg
hijklmn
opqrst

convert to:

\"abcdefg\"
\"hijklmn\"
\"opqrs         


        
7条回答
  •  鱼传尺愫
    2020-12-30 21:44

    I think the sed and awk are the best solution but if you want to use just shell here is small script for you.

    #!/bin/bash
    
    chr="\""
    file="file.txt"
    cp $file $file."_backup"
    while read -r line
    do
     echo "${chr}$line${chr}"
    done <$file > newfile
    mv newfile $file
    

提交回复
热议问题