Find all lines in a file with a certain character at a certain position

47,575

Solution 1

The solution proposed by @rahmu is simple if you look for low positions, but what if you look for the character number 25? Put in 25 dots?

In such a case the following solutions could be at hand. With grep

grep '^.\{24\}a' input >output

With awk

awk -F '' '$25 == "a"' input >output

Solution 2

This should answer your question:

grep -e "^..a" < input > savefile
Share:
47,575

Related videos on Youtube

Chaudhary Muhammad Umair Khan
Author by

Chaudhary Muhammad Umair Khan

Updated on September 18, 2022

Comments

  • Chaudhary Muhammad Umair Khan
    Chaudhary Muhammad Umair Khan over 1 year

    I have a lab question asking me to use grep with a regex pattern to match every word where the third letter from the beginning of the line is an "a" and save it with a redirect. How can I do that?

  • Admin
    Admin about 12 years
    Nice and simple solution. I don't think -e is even needed here - like grep ^..a < input > output should suffice.