How to print the first 7 characters of each column

Hello all,

I have a data like this:

X:04252	X:05524	X:04176
X:05509	X:05524	X:04674-
X:1662912	X:10181
X:16491	X:05506

X:05216-	X:05488

X:46872	X:08471[]
X:04834	X:30170

The except result is like this:

X:04252	X:05524	X:04176
X:05509	X:05524	X:04674
X:16629	X:10181
X:16491	X:05506

X:05216	X:05488

X:46872	X:08471
X:04834	X:30170

That is to say, I want to print the first 7 characters of each column (and lines that including the empty lines). Everybody who knows, please give a hand. Thanks in advance!

awk '{print substr($0,1,7)}' inputfile

My bad. Each column is

awk '{for(i=1;i<=NF; i++) {$i=substr($i,1,7) }
       OFS=" "; print $0} ' infile
1 Like
awk '{for(i=1;i<=NF;i++) $i=substr($i,1,7)}1' file
1 Like