0

How do i extract lines from a text file which satisfy this regex ^2.

I am using linux.

I know grep is able to extract the number of lines but i would need them to be output to a text file.

Is it possible to use grep or other solutions are better? The text file is about 20gb

2

1 Answer 1

1

grep is a solution. You have to protect with a \ the special character ^ in the the expression:

grep -n "\^2" My2GbFile.txt  > MyOutputLog.txt

If you don't want the line number write grep without the -n.

References:

[^...] Matches any single character that is not in the class. For example, [^/]* matches zero or more occurrences of any character that is not a forward-slash, such as http://. Similarly, [^0-9xyz] matches any single character that isn't a digit and isn't the letter x, y, or z.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .