Remove a character and assign result to a variable

I am reading lines from a file that contain a number sign (#) before a three or four digit number:

#1043
#677

I can remove the '#' and get just the number. However, I then want to assign that number to a variable and use it as part of a path further on in my program:

/mydir/10/1043 for example

print -n {$second#?} gives me the 1043 but I have been unsuccessful assigning this result to a variable - I tried company = {$second#?} but company has no value.

I'm new to this, so any help would be appreciated.

You can use like below , a is the file name

>cat a
#1043
#677
>while read num junk ; do var=`echo ${num#\#}`; echo $var; done < a
1043
677

I see num is the variable; what is junk?

Its just a variable ,added to take any other input that may present in the file ,
like

#1043 asd #Here asd will go to junk

If you are sure you have only one word per line ,you can skip this.

1 Like
printf -v number "%s" ${second#\#}

Now, what you want lives in a variable named `number'

1 Like
company=${second#\#}

(And var=${num#\#} )
No space around the = !
printf -v var only works in bash.