0

Assume I have this command: ./clang-$j.out >> clang-result.txt and the each output for clang-$j.out is a fixed-length hash value (each program per line), however, I want to distinguish them by adding a prefix to the beginning of each line. For example, I want to add "1-" where is number comes from the variable j.

I've made some effort to do this but I still cannot figure out how to do.

1

You can output the number from the variable before running each program; in your loop:

printf "%s-" "${j}" >> clang-result.txt
./clang-$j.out >> clang-result.txt
0

You can add something like

prefix=`basename $0 | cut -d"." -f1 | cut -d"-" -f2`
echo ${prefix}-HASH

in the clang-$j.out scripts. It should give you the sequence in the prefix variable. Now you can use this in the output of the script.

  • Thank you for the reply, however I will not know the sequence of variable j before running them, some .out files will be skipped if the program won't run. Is there a method to add prefix while my script is running? – Yang Xia Apr 27 '15 at 13:08
  • I suppose that you know it when you create the script clang-$j.out since it is part of the filename. Do not really know what is done in this script nor how it is created so I can only get the value of $j this way (out of the filename). – Marco Apr 27 '15 at 13:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.