Reputation: 1173
When attempting to redirect output to a directory I get the following error.
-bash: ua/: Is a directory
I know it's a directory. How do I redirect my output to it? Below is what I'm attempting. Thank you.
for file in .; do cut -d '"' -f 4 $file > ua/; done
Upvotes: 2
Views: 3269
Reputation: 7634
The <
redirection operator takes the output of a program and puts it in a file. Naturally, directories can't have "contents" the same way a file can, so this operator does not make sense for directories. That's why you get the error.
What I think you're trying to do is put the transformed contents of the file into a new file of the same name inside the directory. Again, the redirection operator has no notion of the source of its input - no idea that originally came from a file, let alone what that file is called. That being said, just redirect to a file of the same name inside the directory:
for file in ./*; do cut -d '"' -f 4 $file > ua/$file; done
Edit: The next problem you'll face is that your for file in .
isn't doing what you expect. In fact this "loop" only ever loops once, with $file = ".". You probably want to utilise an expansion and do something like for file in ./*.txt
to iterate all the text files for example.
Upvotes: 2