Q:

find and replace using linux

I am trying to transfer a text using regex to match : O followed by space and a random number and then a new line 
Example :
fffffffffffffffffffffffffffffffO 11

ffffffffffffffffO 145

fffffffffffffffffffffffffO 257

fffffffffffO 47

fffffffffffffffffffO 1

ffffffffffffO 85

fffffffffffffffffffffffO 144

fffffffffffffffO 356

and make it like this :
fffffffffffffffffffffffffffffff

ffffffffffffffff

fffffffffffffffffffffffff

fffffffffff

fffffffffffffffffff

ffffffffffff

fffffffffffffffffffffff

fffffffffffffff

using sed or awk ...
any idea ?

A:

sed
sed -i 's/O [0-9]\+$//' file

A:

You can use this:
awk -F "O" '{ $2=""; print $0}' file.txt

or the shorter version of Jotne:
awk -F\O '{$2=""}1'

As glenn jackman suggests it, you can print only the needed part:
awk -F "O" '{ print $1}' file.txt

However, these commands don't care if there is another O in the line and if there is a number or not at the end of the line.

