I have a Java program that concatenates two text files. So, I have file1.txt and file2.txt and all the records from file1.txt are merged with file2.txt ON file2.txt. After concatenation, file2.txt is sorted numerically. However, file2.txt has a header and I need to find a way to ignore that header(not delete, ignore!) when merging the files because it gets messed up with the records after being sorted.
Please help me find a way to ignore the first line of file2.txt
Here is the code:
public static void sortRecords(String fileName, String overflow) {
String s = null;
String main_file = fileName;
String overflow_file = overflow;
String command = "sort -nk1 " + fileName + " -o " + fileName;
try {
//cat
Process merge = new ProcessBuilder("/bin/bash", "-c", "cat " + overflow_file + " >> " + main_file).start();
//sort
Process sort = Runtime.getRuntime().exec(command);
} catch (IOException e) {
}
}
Example:
file1.txt
2 ABC
3 ABC
file2.txt (initially blank, except the header)
ID Name
file2.txt (after concatenation and sort)
ID Name
2 ABC
3 ABC
After concatenation, I empty file1.txt. When user adds records, they are initially stored in file1.txt and after a certain number of records, they are concatenated with file2.txt. So, the problem appears when adding records(besides the first time). They somehow get messed up, something like this:
file2.txt
3 ABC
ID NAME
1 ABC
2 ABC