我想知道是否有人能帮我解决这个小问题。我想通过网页查看文本文件。但是,文本文件没有换行符或格式。
有没有办法在查看时临时添加换行符?
我想通过shell脚本实现这一点。
示例文本文件:

    This is a sample text file.

    Same concept.

    Text has no format. 100 of lines...

也许不是最好的解决办法。。。但我用了下面的方法来完成这项工作:
解决方案:
    FILE=$rpt

    while read LINE; do
        echo "$LINE<br>"
    done < "$FILE"

最佳答案

您可以尝试以下脚本:

#!/bin/sh

FILE=$1
TEMP=$(mktemp /tmp/XXXXXXXX.html)
BROWSER=firefox

{
    echo "<html><head></head><body><div>"
    while read LINE; do
        echo "$LINE<br>"
    done
    echo "</div></body></html>"
} < "$FILE" > "$TEMP"

"$BROWSER" "$TEMP"
# sleep 5  ## If your browser launches in the background. Firefox doesn't.
rm -f "$TEMP"

将其作为sh script.sh /path/to/file.txt运行。

关于linux - 在 View 上将换行符添加到文本文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18626441/

10-11 22:55
查看更多