Can't figure out how to find specific characters in specific columns

I am trying to find a specific set of characters in a long file. I only want to find the characters in column 265 for 4 bytes.

Is there a search for that? I tried cut but couldn't get it to work.

Ex. I want to find '9999' in column 265 for 4 bytes. If it is in there, I want it to print out the whole line.

Thanks for any advice.

Try:

awk -v W="9999" 'substr($0,265,4)==W' infile

Thanks! I'll give that a shot.

Try like..

awk '{if($265=="9999") {print $0}}' test.txt 

The OP has mentioned that he/she needs to check the 4 characters in a line/record starting at the 265th column. 265th column will never be the 265th field for awk (in case of splitting on white-space(spaces and/or tabs)).

Correct. But there may be non POSIX compatible extensions, like in e.g. mawk,

Still you would need to phrase the condition like $265$266$267$268=="9999" . Might be worth a shot.

I think this FS="" also not supported by all extensions.

Thanks everyone. The original answer actually worked for my purposes. Now, is there any way to remove those lines from the file and put them in another file?

I was able to put them in another file, but i can't get them to be removed from the original.

Thanks again.

Rule of thumb is, never edit your originals. One program bug and your input data has been irreversibly trashed. Use the original as a template to generate other things from; if it doesn't work the first time, nothing lost, edit your program and try again.

Thanks. I have copied my original file.

Good, you can follow my advice then and do program < originalcopy > original

Sorry, i don't see any example that you sent on how to strip out the records in question.

It's the opposite of the original solution see change in red:

awk -v W="9999" 'substr($0,265,4)!=W' infile