I have a text file with several columns of text and values. This structure:
CAR 38 DOG 42 CAT 89 CAR 23 APE 18
If column 1 has a String, column 2 is not (or is it actually a String). And vice versa: if column 1 is empty, column 2 has a row. In other words, an βobjectβ (CAR, CAT, DOG, etc.) occurs either in column 1 or in column 2, but not in both cases.
I'm looking for an efficient way to consolidate columns 1 and 2 so that the file looks like this instead:
CAR 38 DOG 42 CAT 89 CAR 23 APE 18
I can do this in a Bash script using while and if, but I'm sure there is an easier way to do this. Can anyone help?
Hooray! Z
source share