File content as below:
Text1:
text_1: Text1 text_1
text_2:
- text
- file1:\\
- file2:\\
Text2:
text_1: Text2 text_1
text_2:
- text
- file3:\\
Text3:
etc
Output: print "file:\" entries for given Textn. Any idea how to achieve this using sed/awk commands in Linux.
Example: test.txt file contents as below:
$ cat test.txt
Text1:
text_1: Text1 text_1
text_2:
- text
- file1:\\
- file2:\\
Text2:
text_1: Text2 text1
text_2:
- text
- file3:\\
Text3:
etc
tried below grep command as suggested and it prints all "file:\" entries in test.txt file. For "Text1:" match all I need is file1:\ and file2:\ as output and For "Text2:" match file3:\ only.
grep
, something likegrep -E 'Test[0-9]+|file[0-9]+:' the_file
. UNTESTED – waltinator Jul 28 '23 at 07:09yq
– Chris Davies Jul 28 '23 at 08:04yq
, it's worth noting that perl, python, and many other languages have yaml parsing libraries....and if you're doing more than just simple extraction from an existing yaml file it would be better to use one of those - bash really isn't suited to data processing itself, it's good at coordinating the execution of other programs to do that. – cas Jul 29 '23 at 01:00grep
command you tried from the question? – AdminBee Aug 03 '23 at 12:41