Shell script read missing last line

前端 未结 7 1189
逝去的感伤
逝去的感伤 2020-11-22 12:57

I have an ... odd issue with a bash shell script that I was hoping to get some insight on.

My team is working on a script that iterates through lines in a file and

7条回答
  •  盖世英雄少女心
    2020-11-22 13:39

    Use sed to match the last line of a file, which it will then append a newline if one does not exist and have it do an inline replacement of the file:

    sed -i '' -e '$a\' file

    The code is from this stackexchange link

    Note: I have added empty single quotes to -i '' because, at least in OS X, -i was using -e as a file extension for the backup file. I would have gladly commented on the original post but lacked 50 points. Perhaps this will gain me a few in this thread, thanks.

提交回复
热议问题