Assinging output of cut command

Hi,
I have the files in the following files in a folder
19996587342
19487656550
19534838736
And i need to get the first 6 characters from the abvoe files
so i used the following script

#!/bin/ksh
 
for i in 19*
 do
  txt= `$i | cut -c -6`
  echo "$txt"
 done

The error is at line no. 5: command not found
Please suggest me .
Thanks

1 Like

What you are doing is to execute the files. You probably need something more like this:-

#!/bin/ksh
 
for i in 19*
 do
  txt=`cut -c -6 $i`
  echo "$txt"
 done

The cut command will get you the sixth character from the file referred to by $i You will also notice that I have removed the space after the =.

How big are the files? More than one record might give odd results. If you want the sixth character from the first line only, then:-

#!/bin/ksh
 
for i in 19*
 do
  txt=`head -1 $i | cut -c -6`
  echo "$txt"
 done

I hope that this helps.

Robin
Liverpool/Blackburn
UK

1 Like

It worked , Thank You

use echo $i and not $i