cut: |: Нет такого файла или каталога

2910
mahidhar
while read line do echo $line calendar_date=$(cut -d\ -f1 $line) hr_of_day=$(cut -d\ -f2 $line) echo "date: $calendar_date hr: $hr_of_day"  done < $FILE 

Я получаю следующую ошибку:

date: hr: 2011-06-30 | 23 cut: 2011-06-30: No such file or directory cut: |: No such file or directory cut: 23: No such file or directory 
-1
Вы смотрели вверх `cut` ручной ввод? Вы пытались понять смысл сообщения об ошибке? Что вы пробовали? MariusMatutiae 8 лет назад 1
$ line читается как параметры файла. Можно написать что-то вроде `hr_of_day = $ (echo" $ line "| cut -d \ -f2)`, если у вас нет кавычек во входящем тексте. le_top 7 лет назад 0

2 ответа на вопрос

4
choroba

cut understands the $line argument as a file name. If your shell is bash, you can use the <<< here-word:

cut -d' ' -f1 <<< "$line" 

But, there's no need to call external commands, bash can do it with parameter substitution:

date=$ # Delete from | to the right. hour=$ # Delete up to |. 
1
Rohit Malgaonkar

on mac os x terminal

test="$(echo '1\2\2016' | cut -d '\' -f3-)" echo "year:$test" prints year from test with an echo string year:2016 or echo "year:"$(echo '1\2\2016' | cut -d '\' -f3-)"" prints year from test with an echo string year:2016 

try this (similar to above)

calendar_date="$(cut -d '\' -f1 $line)" hr_of_day="$(cut -d '\' -f2 $line)" echo "date: $calendar_date hr: $hr_of_day" 

for input reads this works with echo

while read x do echo $x | cut -c3,7 #echo $x | cut -c3,7 (for range of letters) done 
$ line читается как параметры файла. le_top 7 лет назад 0
отредактировал первое сообщение, пожалуйста, попробуйте и дайте нам знать ... Rohit Malgaonkar 7 лет назад 0

Похожие вопросы