【发布时间】:2015-03-23 16:40:10
【问题描述】:
我正在尝试删除日期函数的换行符并让它包含空格。我正在使用以下方法保存变量:
current_date=$(date "+%m/%d/ AT %y%H:%M:%S" )
我可以通过 echo $current_date 看到这是我需要的正确格式。 但是,当我需要使用这个变量时,它不会按照我想要的方式运行。
awk '(++n==47) {print "1\nstring \nblah '$current_date' blah 2; n=0} (/blah/) {n=0} {print}' input file > output file
除非指定,否则我需要将日期保留在当前文本行中并且不使用换行符继续。
提前致谢。
【问题讨论】:
-
使用
echo "$current_date",而不是echo $current_date来查看$current_date的实际值。您尝试在 awk 脚本中使用 shell 变量的方式也是错误的。发布一些示例输入和预期输出,以便我们为您提供帮助。
标签: bash awk formatting