Page 2 of 2
Re: Need a command to delete certain entries in a text file
Posted: Tue Jan 03, 2023 5:18 am
by amethyst
@Burunduk
That last script of yours does not work for me. I'll go with the following which gives the desired results. Topic marked as solved:
Code: Select all
D=/tmp/.packages
tmpfile=`mktemp`
for file in "$D"/*; do
while read -r line; do
[ -f "$line" ] && printf "%s\n" "$line"
done <"$file" >"$tmpfile"
mv "$tmpfile" "$file"
done
find "$D" -mindepth 1 -empty -delete
Re: Need a command to delete certain entries in a text file
Posted: Tue Jan 03, 2023 5:42 am
by Burunduk
amethyst wrote: Tue Jan 03, 2023 5:18 am
That last script of yours does not work for me....
This is not a very informative bug report.
Well, probably you are using the #!/bin/sh
shebang. In this mode bash doesn't support process substitution. If the directory is flat, your code will work as it is.
Code: Select all
root# bash -c 'head <(echo foo)'
foo
root# sh -c 'head <(echo foo)'
sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `head <(echo foo)'
Re: Need a command to delete certain entries in a text file (Solved)
Posted: Wed Jan 24, 2024 4:56 pm
by amethyst
Asked ChatGPT to explain the code just to see the response. It's quite good, didn't expect to get such a complete and well-explained answer. https://chat.openai.com/share/2cbb6711- ... 37f8ffcadf