gpt4 book ai didi

linux - 意外的行尾 - dos2unix 不会修复它

转载 作者:太空宇宙 更新时间:2023-11-04 10:01:22 24 4
gpt4 key购买 nike

我有以下代码:

#!/bin/bash

set -o errexit
set -o nounset
set -o pipefail
set -u

se () { sed -n 's/\s*r('"$1"').*|r| =\s\+//p'}

### gets the number of cell opt steps
exec 0<"DEMLIR.out"
while read -r line
do
gawk 'BEGIN{FS="OPTIMIZATION STEP:"} {print $2}' | tr -s " "
done>results

sed -i '/^$/d' results
#sed -e 's/^[ \t]*//' results

step=$(tail -n 1 results)
echo "${step}"

### gets the number of steps in each geo_opt output
for i in $(seq 1 $step)
do
exec 0<"DEMLIR-GEO_OPT-$i.out"
while read -r line
do
gawk 'BEGIN{FS="OPTIMIZATION STEP:"} {print $2}' | tr -s " "
done>results_geo_$i

sed -i '/^$/d' results_geo_$i

step_geo=$(tail -n 1 results_geo_$i)
echo "${step_geo}"

### goes through each line in distance.out and prints distances to array
exec 0<"DEMLIR-GEO_OPT-$i-distance-1.coordLog"
while read -r line
do
for j in $(seq 0 $step_geo)
do
"$line" | se
paste -d' ' <(printf '%s\n' $j) <(se 1,5) <(se 2,5) <(se 2,8)

done
done

done>DEMLIR_task.txt

我尝试运行这个程序,但我一直在第 53 行收到意外的行尾错误。我看到这个问题已经有了答案,但是当我尝试 dos2unix它说dos2unix:将文件 script_step.sh 转换为 Unix 格式...但仅此而已。当我再次运行代码时,它不会工作。

我预计在最后一个 for 循环中会出现一些错误,所以如果您看到一些错误,也可以指出它们。但是,如果它们与原始问题无关,那么您可以忽略它们。

最佳答案

问题出在这里:

se () { sed -n 's/\s*r('"$1"').*|r| =\s\+//p'}

前需要一个分号或换行符。否则,它被视为 sed 参数的一部分。

关于linux - 意外的行尾 - dos2unix 不会修复它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55942010/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com