Artificial intelligent assistant

Remove everything from a text file between ":" and "\n" I have a big text file (263 lines) that contains lines something like these: image_name.jpg: *lots of spaces* JPEG image data, JFIF standard 1.01, resolution (DPI), density 96x96, segment length 16, baseline, precision 8, 1024x768, frames 3 \n image_name.jpg: *lots of spaces* JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, comment: "CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), quality = 70", progressive, precision 8, 960x540, frames 3 \n image_name.png: *lots of spaces* PNG image data, 752 x 760, 8-bit/color RGBA, non-interlaced \n How can I remove all the text between _**:**_ and _**\n**_ at once?

With `cut`:


cut -d: -f1 file


With `sed`:


sed -e 's/:.*//' file


With `awk`:


awk -F: '{print $1}' file


With GNU `grep` or many BSD `grep`s (but not POSIX `grep`):


grep -o '^[^:]*' file


`cut` is the shortest one.

If you want to modify the file in-place, your `sed` may have an option `-i` that does so - but how exactly that works depends on your platform. Otherwise, `> file2 && mv file2 file` on the end of any of them will work.

Alternatively, with `ed`, in-place everywhere:


printf ',s/:.*/\
w\
' | ed file

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy d99e2e90867729e63d5de283ff02afba