I have a text file and am trying to extract the data in the first row (or line) of the file, where each data is saved as a list (so each point is saved on it’s own line) in a new file.
example data.txt:
Name Col Samp1 Samp2 Samp3 Samp4 Samp5 Samp6
Car1 Red 49.3 43.2 54.3 52.3 12.5 76.8
Car2 Blu 56.3 12.4 85.4 67.1 24.5 32.5
and so on..
I would like a new list to look like this, and saved to a new file called samps.txt:
Samp1
Samp2
Samp3
Samp4
Samp5
Samp6
I am very new to shell scripting and could use all the help anyone can provide.
Read the first line into a variable
Split the string into words
Loop through the words and output them to a file
In your case, you want to drop the first two column values. You can slice the array by using
${WORDS[@]:2in your for statement. Alternative, you can test the values inside the for loop before echoing them to the file.