I am using sort -k1,1 -k2,2 srcfile> tgtfile...
But this is throwing the error "No space in device" as the src file contains 180 million rows in it.
How to fix this issue??
GNU sort can sort files larger than what would fit in your RAM.
It does that by sorting a part of your input that does fit, writing the result to a temporary file, moving on to the next input part, sorting that, writing it to a temporary file and so on. Afterwards, it merges all the partial sorted files into one sorted output.
The file system that these temporary files are written to needs to be large enough to keep the whole content of the input file, potentially multiple times. GNU sort is not very smart about choosing the directory the temporary files are written to - it just uses the system default (typically, /tmp).
To mitigate your problem, tell sort to put the temporary files next to the target file (they will be automatically cleaned up, anyways), using
sort --temporary-directory=. -k1,1 -k2,2 -o tgtfile srcfile
$TMPDIR, falling back to system default like GNU sort does at least seems the smartest thing to do to me. I wouldn't want it to take it upon itself to start using file systems that have not been intended to store temporary data.
sort implementations from the 70s already stored temporary data to disk.
tgtfiledoes not have enough space to save the file. Showing any information about the the space available on your devices (dh -h) could help someone in figuring out what the specific issue is.