Delete characters from each line until meet character ":"

Hello,

I have file that looks like this :

765327564:line1
94:line2
7865:line3
.....
765322:linen

I want to cut all the digits from the beginning of each line up to ":" character and to have everything like this :

line1
line2
line3
.....
linen

P.S : content of line1 ... linen may contain ":" character so to eliminate what I don;t want from each line with echo $line | cut -d ":" -f 2 will not work well.

any ideas?

THX.

you can use nawk , awk , gawk:

nawk -F":" '{print $NF}' infile > outfile
1 Like

Yes, thanks, this is what I was looking for.

---------- Post updated at 09:31 AM ---------- Previous update was at 09:29 AM ----------

One more question : do you know how to close a thread on this forum ?

sed 's/.*://' infile
1 Like

sorry , but I didn't see your important note that the lines may contain another ":" , my first code will not work if this is true ,kindly use below python code:

import re

fin = open("infile.txt",'r')
fout = open("outfile.txt",'w')
for line in fin:
     print(re.subn(r".*?:","",line,count=1)[0] , file=fout , end="")

fin.close()
fout.close()

BR

---------- Post updated at 17:47 ---------- Previous update was at 17:42 ----------

this will not work for below:

using bash:

$ echo "765327564:line1 hdvir:kvoir" | sed 's/.*://'
kvoir

I know, but the OP was happy with the previous solution that did just that and so I thought that is what he meant. Otherwise he could use this:

sed 's/[^:]*://' infile
1 Like

Yes, NOW it works.

THX!

Ok, but then you were close with your original cut command:

cut -d: -f2- infile

hmmm.. -f2- .
yup, I'm learning that now. good stuff.