sed command

Hi all,

I have a file >> data30000.stop. I want to have an output from it which will be the extension+the number i.e stop30000. I used

extname=`echo $file | sed 's/.*\.//'`

and I get stop, I want the 30000 so it reads stop30000

Thank you

Please become accustomed to provide decent context info of your problem.
It is always helpful to carefully and detailedly phrase a request, and to support it with system info like OS and shell, related environment (variables, options), preferred tools, adequate (representative) sample input and desired output data and the logics connecting the two, and, if existent, system (error) messages verbatim, to avoid ambiguities and keep people from guessing.

That "file" is a file name? If it's a name, is it held in a variable? Another file?

Try:

extname=$(echo "$file" | sed 's/[^0-9]*\([0-9]*\)\.\(.*\)/\2\1/')
1 Like

Thank you Scrutinizer, exactly what I wanted.:b:

Hello Theo Score,

Could you please try following also and let me know if this helps you.(Considering that your variable will be same as shown sample)

val=$(echo "$file" | awk -F'data|[.]' '{print $NF$2})

Hello Scrutinizer,

I think ) is missed at the end of the code.

Thanks,
R. Singh

1 Like

Hi Ravinder, thanks a lot for your input. It works well now.

Cheers:b:

echo ${FILENAME#*.}${FILENAME//[[:alpha:][:punct:]]}
stop30000