copy lines data between 2 patterns in shell scripting

前端 未结 2 1575
别跟我提以往
别跟我提以往 2021-01-29 13:17

This is my source.php file i want copy line number and line code if pattern matches between \'<(single quot less than) and \'>;(sinle quot greater than comma) <

相关标签:
2条回答
  • 2021-01-29 13:40

    Try the following command:

    sed -ne "/'</,/>'\;/{=;p}" source.php | sed '/./N;s/\n/ /' > wdestination.php
    

    The = prints the line number of the pattern. The second sed command puts the line number on the same line as the text, otherwise it would be printed on separate lines.

    0 讨论(0)
  • 2021-01-29 13:57

    if you want to copy all lines that happens to be between '< and >'; into the destination.php :

    sed -ne "/'</,/>'\;/wdestination.php" source.php
    
    0 讨论(0)
提交回复
热议问题