Convert Column Values to a Range of Values

I have a list of columns with values that I need to transform into a row containing the range of each column. For example:

"Column A"
1
2
3
4
10
12
14
15
16
17
18

"Column B"
1
4
5
6
7
10

etc.

I want the output to be like this:

"Column A" 1-4, 10, 12, 14-8
"Column B" 1, 4-7, 10

I'm just starting with shell scripting, so a code with a description of how to adjust variables would be greatly appreciated!

This sounds more like a homework assignment than a "real" project. If this is a homework assignment, you need to close this thread and start a new thread in the Homework and Coursework Questions forum.

If not, you need to provide a lot more information about the input columns and the output you want.

Are the input columns in separate text files, a single text file with all of the data in a single column and some particular input lines indicating the start of a new column, actual columns in a text file (with what used to distinguish field boundaries), or something else? Are the column titles all in double quotes? Are the values in the input columns sorted (and, if not, is the script supposed to sort the output to appear as though the input had been sorted), or should it be a comma separated list of increasing (or increasing and decreasing) range values in the order in which they appeared in the input? (And, please use CODE tags to show sample input, sample output, and code segments!)

What variables do you want to adjust (and why)?

If you want us to help you learn how to do something, you need to provide us with more information about what you have (what shell, operating system, and operating system version are you using), what you want to do, and what resources you have to do it. This is not a forum for you to give vague comments about a project you'd like for someone else to design and implement for you.

Here's an example, assuming the column separator is a pipe:

awk -F"|" '{
	switch (NR) {
		case 1:
			t1 = $1 " ";
			t2 = $2 " ";
			next;
		case 2:
			t1 = t1 $1; n1=$1;
			t2 = t2 $2; n2=$2;
			next;
		default:
			if ($1!=n1+1 && $1!="") {
				t1 = t1 (p1!=n1? "-" n1:"") ", " $1;
				p1 = $1;
			}
			if ($2!=n2+1 && $2!="") {
				t2 = t2 (p2!=n2? "-" n2:"") ", " $2;
				p2 = $2;
			}
			if ($1 != "")
				n1 = $1;
			if ($2 != "")
				n2 = $2;
	}
}
	END {print t1 (p1!=n1? "-" n1:""); print t2 (p2!=n2? "-" n2:"")}
' file

Sorry, this is not homework, I am not a student anymore. I apologize for my inexperience, I did not know how to use code tags. By variables I mean, for example, if the code requires the path to a file, it would be nice to know that is what an abbreviation means. The data is in several formats, as I was not sure what would be easiest to use - I have it in excel and txt formats (single column with the column names followed by their data, as well as in multiple columns), and the data is in increasing order with no quotes anywhere. I would like the output to be the column name in one cell and then the data in one or more cells (in increasing order, which is the order they are in currently) as it appears above. I am using a new apple computer with Xcode to try to write various "awk" commands to no avail, but due to my lack of experience I am not sure exactly what to use.
Thanks much for the suggestion, jethrow, I will try it!

Since you have an excel file containing the data you want to process, use the export as CSV file feature in excel to produce a text file containing your data with commas separating columns in your data. Post a representative sample of your filename.csv file (in CODE tags) and show us the corresponding output that you want the script to produce (in CODE tags).

Also show us the output of the command uname -a so we will be able to tailor the script to the capabilities provided by your operating system.

We may then be able to help you write an awk script to process your data.

PS I haven't examined jethro's suggested awk script in detail, but it uses some constructs (such as the switch() statement) that are not available in standard versions of awk. And it seems to assume that your input file always contains two columns. (I assumed that the

line in your first post meant that there could be several more columns in your input. I'm sure you'll explain how many columns could appear in your input in your next post when you show us your sample input file.)