If these lines are stored in a file (call it input_file ):
# input_file: abc.out abc.out abc.out def.out def.out def.out
You can do:
sed -i 's/\.out//g' input_file
And this will eliminate any occurrence of the .out substring from this file.
Explanation:
sed : call the sed tool to edit text streams.-i : use the option "in place" - this changes the input file that you provide, instead of writing to stdout's/\.out//g' : use regex to remove .out . g at the end means deleting all occurrences.input_file : specify the input file
If these lines are stored in variables:
var1="abc.out"
You can use parameter substitution :
var1=${var1%.out} echo "$var1" abc
Explanation:
sampson-chen
source share