Delete records by string and position

How do i delete the records when we have string "abcd" at position 21 to 24. The file is huge in size. Any help is appreciated.
Sample data given below

eiojfcdf oijjfdm ijdabcd234vffmv
eojfirr jfdiopem ijaabb456irkmd
aodniiuielc uejdocvoabcd957wpdjf

You have been asking questions and getting help from us for six years now...

What tools do you think might be used to solve this problem?

What have you tried to solve this problem on your own?

What operating system and shell are you using?

Thanks for your reply.
I thought a script which reads the file line by line then check for the string at particular position then if string found do the deletion could solve this problem.
i used

 sed '/pattern/d' filename 

but the string "abcd" occuring other than the position 21 to 24 are also deleted. I want to delete only if string "abcd" is available in said position.

OS - SuSE FUSE Version 4.3.0 , shell bash

If you want to match characters in a certain position with sed you have to create a basic regular expression that matches the desired number of characters at the start of the line followed by the characters you want in that certain position. Try:

sed '/^.\{20\}abcd/d' filename
1 Like

That worked. Thanks a lot. :slight_smile: