Why does this script work with the old version of the file?
I want to remove the first line of a csv if the line contains the text KP_TITEL
If i test the script with an exit after sed everything works fine. But as soon as I want to test it with the while loop the file still contains the first line.
Any Idea?
sed -i '/KP_TITEL/d' "$1"
# read data
input=$1
while IFS=';' read -r f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13
do
other things
done < "$input"
I’m not sure what the option
-idoes forsedbut usually,sedis a stream editor which processed the input and writes the result to stdout. In your case, the output is lost and then, the old file is read again by while. Try this instead:The pipe symbol will change the
stdinof the while loop (and hence thereadcommand).I continue the line with
\since I find this more readable than:And to delete the first line, you should use either
or (cheaper)