0

I am using a shell script where I split a file according to the values of a certain column (using awk). My script is in a folder X, though, and I need the resulting files to be created in a folder Y. How can I do that?

This is how the files are currently generated:

awk -F';' 'NR==1{h=$0; next}
!seen[$3]++{f="FILE_"$3".txt";print h > f} 
{print >> f}' $input
4
  • 1
    Depends on your script. Does it print to standard out, or is the output path hardcoded in the script itself, or…? Probably best to post the script here (or at least pertinent sections).
    – Sparhawk
    Commented Nov 9, 2015 at 1:15
  • Show some code so it's more clear what your question is. Seeing how you currently create the files is probably all that's needed.
    – Lizardx
    Commented Nov 9, 2015 at 1:16
  • Sorry about that. I've updated my question with the code I'm using.
    – Geralt
    Commented Nov 9, 2015 at 1:20
  • 1
    Just as an aside, folder is a windows term, in unix type systems we have files and directories. Well, actually you have that in windows too, but they just like to pretend that windows is different.
    – Lizardx
    Commented Nov 9, 2015 at 1:55

1 Answer 1

2

That should do it, I think. Just pass awk the full path of the directory you want the file created/updated in.

awk -F';' -v path=/path/to/alt/directory/ 'NR==1{h=$0; next}
!seen[$3]++{f= path "FILE_" $3 ".txt";print h > f} 
{print >> f}' $input

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .