小编SDG*_*ero的帖子

为什么我的Bash脚本将<feff>添加到文件的开头?

我写了一个脚本来清理.csv文件,删除一些坏的逗号和坏的引号(坏,意味着它们打破了我们用来转换这些文件的内部程序),使用sed:

# remove all commas, and re-insert the good commas using clean.sed
sed -f clean.sed $1 > $1.1st

# remove all quotes
sed 's/\"//g' $1.1st > $1.tmp

# add the good quotes around good commas
sed 's/\,/\"\,\"/g' $1.tmp > $1.tmp1

# add leading quotes
sed 's/^/\"/' $1.tmp1 > $1.tmp2

# add trailing quotes
sed 's/$/\"/' $1.tmp2 > $1.tmp3

# remove utf characters
sed 's/<feff>//' $1.tmp3 > $1.tmp4

# replace original file with new stripped version and delete .tmp files
cp …
Run Code Online (Sandbox Code Playgroud)

linux bash sed cp

17
推荐指数
1
解决办法
3万
查看次数

从通过arg提供的日期计算第二天的日期的技术?

我在解决这个问题时遇到了一些麻烦.

我有一个脚本,用于检查脚本调用指定的日期之后生成的日志文件.这是因为直到第二天才会获取为指定日期数据提取的文件.当cron在早上运行时,日志文件将在第二天的文件名中包含时间戳,而不是arg指定的日期.我需要保持arg相同,因为我们组的标准约定只指定数据引用的日期,而不是cron作业提取的日期.该日期(在此脚本中以$ NOW存储)对其他操作使用了很多.

所以现在我正在做这个疯狂的嵌套条件事件(实际上有效,但我觉得它很可怕):

#Setup the date, and variables
TENANT=$1
DATE_ARRAY=(`echo $2 | sed -e 's/\// /g'`)
MONTH=(`echo ${DATE_ARRAY[0]}`)
DAY=(`echo ${DATE_ARRAY[1]}`)
YEAR=(`echo ${DATE_ARRAY[2]}`)
NOW=$YEAR$MONTH$DAY
...

# The next 15 lines or so will iterate the cron log date to the correct
# month or year if the load date is at the end of the month/year.
if [ "$DAY" -eq 28 ] && [ "$MONTH" -eq 02 ]; then
        CRON_NOW=$(($NOW + 173))
elif [ "$DAY" -le 29 ]; then
        CRON_NOW=$(($NOW …
Run Code Online (Sandbox Code Playgroud)

linux bash scripting cron date

2
推荐指数
2
解决办法
3162
查看次数

标签 统计

bash ×2

linux ×2

cp ×1

cron ×1

date ×1

scripting ×1

sed ×1