I have 24 directories in a specific directory (main_directory). Each 24 directory have a text file whose name is DATA.txt.
I need to use grep command to extract below specific pattern for each text file;
2* x = 3800689.6402 y = 882077.3636 z = 5028791.2953
2* x =
part is constant for all DATA.txt. The other numeric numbers are variable. I need to extract above line for each DATA.txt and save them into another text file. Which script I can use for this process?
To recursively search using
grep
, use the-R
option.To search for an exact string, use
-F
, so that2*
isn't treated as a regular expression.To search only on specific filenames, use the
--include
option. Combined:Since you know the name of the target files, you can also do
Or, with
awk
:And Perl:
General approach:
or
specific approach: