I have file file1.txt whose contents are as follows:Date List-----------    Quarter Date         Year Date             Month DateNow I want to read the non space elements from each row of file and to write to a variable.For example for row 2 variable should contain Quarter Year only after removing space.I tried:tail -1 file1.txt > variable1But it doesn't work.
Unix bash/ksh : Selection of first non space character from file from specific line
bash;shell;shell script;ksh
Using sed:variable1=$(< inputfile sed -n '3s/ *//p')variable1=$([...]): runs the command [...] in a subshell and assigns its output to the variable $variable< inputfile: redirects the content of inputfile to sed's stdin-n: suppresses outputsed command breakdown:3: asserts to perform the following command only on the 3rd line of inputs: asserts to perform a substitution/: starts the search pattern *: matches zero or more  characters/: stops the search pattern / starts the replacement string/: stops the replacement string (hence actually replacing with nothing) / starts the modifiersp: prints only the lines where the substitution succeeded