0

I want to copy over all lines in a file (file1.txt) containing Cmd:[41] over to another file (file2.txt)

awk '/Cmd:[41]/' file1.txt > file2.txt

This command doesn't seem to work. The file2.txt is of size 0. However there are lines in file1.txt that contains Cmd:[41]

Is there some specific awk escape character that I should be using. The problem is with [41] part. The other part of the search string seems to work fine.

Allan
  • 12,117
  • 3
  • 27
  • 51
liv2hak
  • 14,472
  • 53
  • 157
  • 270
  • see also: https://www.gnu.org/software/gawk/manual/html_node/Regexp-Operators.html#Regexp-Operators – Sundeep Mar 07 '18 at 03:49
  • Did my answer solved your issue? If it is the case could you put it as correct answer? Thank you – Allan Mar 07 '18 at 07:05
  • 1
    Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See [What topics can I ask about here](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Super User](http://superuser.com/) or [Unix & Linux Stack Exchange](http://unix.stackexchange.com/) would be a better place to ask. – jww Mar 07 '18 at 19:02

1 Answers1

1

You can just change your command in the following way and it will work:

awk '/Cmd:\[41\]/' file1.txt > file2.txt

Explanations:

'/Cmd:[41]/' will match lines that contain: Cmd:4 or Cmd:1 but will not match lines that contain literally Cmd:[41] as [...] are used in regex to define a character range, or a list of characters that can be matched therefore you need to escape them by adding a \ before them.

Allan
  • 12,117
  • 3
  • 27
  • 51