P
P
Printip2021-04-29 15:20:55
linux
Printip, 2021-04-29 15:20:55

How to remove everything up to a character within a string?

Hello!
There is a file file.txt with the content:

1_0_0.jpg 2_0_1.jpg 3_0_8.jpg
6_0_4.jpg 7_0_5.jpg 8_0_9.jpg

how to make sure that everything from the symbol _ to .jpg inclusive is deleted from the line so that
1 2 3
6 7 8 remains

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
N, 2021-04-29
@Printip

str="1_0_0.jpg 2_0_1.jpg 3_0_8.jpg
6_0_4.jpg 7_0_5.jpg 8_0_9.jpg"

echo "$str" | sed -r 's/([0-9]+)[^\.]+\.jpg/\1/g'

S
Saboteur, 2021-04-29
@saboteur_kiev

Look at the result on the screen
sed -r 's/([0-9]+)\S+/\1/g' file.txt
And fix the file right away
sed -ir 's/([0-9]+)\S+/\1/g' file.txt

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question