1836170 Members
4077 Online
110096 Solutions
New Discussion

Re: Sed Question

 
hpuxrox
Respected Contributor

Sed Question

I have the following file,

Abc123
Abc1234
000\Abc1235
101\Abc1236
X01\Abc1237

I want to strip out anything that is before the "\" so the output would be,

Abc123
Abc1234
Abc1235
Abc1236
Abc1237

Thanks
4 REPLIES 4
VK2COT
Honored Contributor

Re: Sed Question

Hello,

Say,m your lines are saved in file ZZZ.Then simply run:

# sed -e 's/^.*\\//g' ZZZ

The result is:

Abc123
Abc1234
Abc1235
Abc1236
Abc1237

Cheers,

VK2COT
VK2COT - Dusan Baljevic
Hein van den Heuvel
Honored Contributor

Re: Sed Question

If there are multiple "\" on the line, the I suspect you still just want the last chunk right. That's what the above will do.

And alternative using awk: awk -F\\ '{print $NF}' ZZZ

And if only data up to the first \ needs to be stripped (unlikely):

sed -e 's/^[^\\]*\\//g' x

Hein.
Dennis Handly
Acclaimed Contributor

Re: Sed Question

>Hein: And if only data up to the first \ needs to be stripped (unlikely):
sed -e 's/^[^\\]*\\//g' x

I assumed you could just remove the "g" but that doesn't work. It seems in your and Dusan's answer, that "g" isn't needed.
Hein van den Heuvel
Honored Contributor

Re: Sed Question

The 'g' is ofcourse not needed.
Sorry. I just cut & paste Dusan first to make sure that worked, then modified.

Hein