Issue
I'm looking to remove (from a file) all lines which match with a number which is at the 34th position with the following command :
sed -n "/^.{33}16184198166000003.*$/!p" inFile >> outFile
It's working with the following command (it's pretty bad I know):
sed -n "/^.................................16184198166000003.*$/p" inFile >> outFile
I can't understand why it isn't working in both cases.
This is some lines from my file:
aaaaaaaaaaasfqfqfqsfqfsqfsqaaaaaa16184198166000003qsdfqesrfzqssdgsdqsfsf zerzer z ez r
sF SDF EZ EZ FF F ZE EFedff<df16184198166000003sssssssssssssssssssssssssssssssssssss
The number to find:
16184198166000003
The number is 17th char long and must be at the 34th position. Each line represent an accounting bill and this number can be present in another position (for example at the 113th position). In this case I must not delete the line.
Solution
I think you're missing the escape sequence on brackets. This worked for me:
sed "/^.\{33\}16184198166000003.*$/d" input.txt > output.txt
Tested on ubuntu 14.04, bash 4.3.11, sed 4.2.2.
If above answer does not work for you, consider using groups:
sed "/^.\(\{33\}\)16184198166000003.*$/d" input.txt > output.txt
Answered By - brunorey