I am writing a simple unix script as follows:
#!/bin/bash
mkdir tmp/temp1
cd tmp/temp1
echo "ab bc cj nn mm" > output.txt
grep 'ab' output.txt > newoutput.txt
I got following error message:
grep : No such file or directory found output.txt
but when I looked into the directory the text is created output.txt…but the type of the file was TXT….I am not sure what it is any help??
You probably have a stray
'\r'(carriage return) on the line with theechocommand. You’re creating a file called"output.txt\r", and then trying to read a file called"output.txt"without the carriage return.Fix the script so it uses Unix-style line endings (
\nrather than\r\n). You can use theunix2doscommand for this. (Note thatunix2dos, unlike most filters, overwrites its input file.)