My requirement is to split a file based on the first field. My file looks something like this :
aaa|12345
bbb|45679
aaa|334564
ccc|qewqw
Now my awk command works just fine and splits the file with respect to the first field value.
awk -F\| '{f=($1); print $2 > f}' /myfile
Result : File name aaa has the below rows :
12345
334564
Now , I want to make it input driven , that is from a script i will enter the value aaa
to this awk command and it will match with $1
and create the file like above. I tried with awk -v to take the value as input, but its not working the way I want it to.
Any help would be much appreciated.
Thanks in advance.