I have a tab-delimited .txt file that has 4 rows and 4 columns. I want to extract numbers (integer, decimal number and scientific notation) from the txt file. The numbers are in row 2-4 and column 2-4 (the first row is the header, and the first column is the rowname). The content of the file is pasted below:
component sigma h2 h2_se
G -5.55758e-19 -0.0964725 26.3887
GxE 6.13144e-18 1.09647 26.3651
noise 0 0 0
This is the desired output:
-5.55758e-19 -0.0964725 26.3887 6.13144e-18 1.09647 26.3651 0 0 0
Any help is greatly appreciated!
Below is some code I tried, which does not yield what I want:
grep -o '0.[[:digit:]]*' myfile
grep -o '[[:digit:]]*' myfile
====================================================
Here's the code that worked for me, and a lot of thanks to @tink!
awk 'NR>1 {printf "%s %s %s ", $2,$3,$4}END{printf "\n"}' myfile
CodePudding user response:
$ awk 'NR>1{$1=""; out=out $0} END{$0=out; $1=$1; print}' file
-5.55758e-19 -0.0964725 26.3887 6.13144e-18 1.09647 26.3651 0 0 0
CodePudding user response:
$ cut -f2- < file | tail -n 2 | paste -s - | tr '\t' ' '
-5.55758e-19 -0.0964725 26.3887 6.13144e-18 1.09647 26.3651 0 0 0