0

My input file has several lines which are each of length of 20.The length of the line is always fixed and I need to extract the first 5 values from each line in the input.txt file.

I have the follow code which I tried but I am not sure why the output.txt is always empty. I am taking the substring from column 1 to column 5, am I missing something is my code logic?

My input file: input.txt

0290This is the firm
12 I need to run the
02930290Time is vals

Sample output.txt:

0290T
12 I 
02930

My code as of now:

awk '{val=substr($0,1,5)} {print $val}' input.txt > output.txt

May someone help me find the code issue?

Inian
  • 80,270
  • 14
  • 142
  • 161
Laura Smith
  • 293
  • 3
  • 13

0 Answers0