0

I have files in a directory:

mkdir in_dir
echo 'a' > in_dir/file1.txt
echo 'b' > in_dir/file2.txt
echo 'c' > in_dir/file3.txt

mkdir out_dir

I have a command that takes input from files using < and writes output to a new file with >. I want to run it on all files in in_dir and write the output to out_dir under a matching file name.

This does the first part, runs a (dummy) command on each file.

#!/bin/zs
for file in in_dir/*;
(cat $file ; echo '1')

I'd like to have 'file1.txt' in out_dir with the content 'a1', 'file2.txt' with 'b1' etc.

3
  • 1
    echo "$(cat $file)1" > "out_dir/$file" Commented Feb 3, 2021 at 19:48
  • 1
    what is the content of out_dir/file1.txt? a or a1? Commented Feb 3, 2021 at 20:19
  • a1, I acknowledge that this wasn't very clear Commented Feb 4, 2021 at 9:21

1 Answer 1

1

You have yourscript which process the information if I understood well. And you can make another script as follow:

#!/bin/bash

IFS=$'\n'

for i in `ls -1 ./dir_in` ; do
    ./yourscript "$(cat ./dir_in/$i)" > ./dir_out/$i
done

unset IFS

Don't forget to take this script chmod +x permission.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.