0

I am using cut to eliminate last two characters of a file:

cut -c1-40 <inputfile >outfile

Before, I have used wc to know the number of characters in the file:

wc -c inputfile

Now I would like to use this information to write a shell script First I have obtained the total of characters in the file and subtracte 3 from that number. I would like to use the content of the variable to use it on cut.

nc=`wc -c < $inputfile`

nc=`expr $nc - 3`

Now I would like to have something like

cut -c1-$nc <inputfile >outfile but it doesn't work.

none given
  • 3
  • 1
  • 3

1 Answers1

0
head -c-2
 -c, --bytes=[-]K         print the first K bytes of each file;
                            with the leading `-', print all but the last
                            K bytes of each file

Or to delete first two characters

tail -c+3
 -c, --bytes=K            output the last K bytes; alternatively, use -c +K
                          to output bytes starting with the Kth of each file
Zombo
  • 1
  • 62
  • 391
  • 407