Skip to main content
deleted 46 characters in body
Source Link
Kishan
  • 113
  • 1
  • 6

I try to uncomment specific lines from a file with patterns in oracle linux 8.6 using bash. There are leading white spaces on certain lines where the comments are not removed. I tried to uncomment the commented lines with sed and grep for matching the patterns. I need to exactly match two numbers from the output. There is one word per column(total 2 columns) in the file each with numbers.

Example: column1:pd19_ORA column2:svg38.

I need to uncomment lines inplace with exact match of 19 and 38 without 190,1900 or 019 etc.. excluding lines such as,

column1:pd**19**_ORA column2:svg**37**  #pd19_ORA svg37 
column1:pd**199**_ORA#pd199_ORA column2:svg**388**svg388 

Code:

sed -n '/\<19\>/,+1p' cmfile|grep '38'|sed -i '/38/s/^#//g' cmfile

Contents of file:

    #pd19_ORA svg38
#pd19_ORA sil38
#pd29_ORA sil37
    

First line is still commented after using sed with inplace but comment of second line is removed.

Output:

    #pd19_ORA svg38
pd19_ORA sil38
#pd29_ORA sil37

How to remove the first line comment which has leading white spaces without removing the leading space?

Expected output:

    pd19_ORA svg38
pd19_ORA sil38
#pd29_ORA sil37

I try to uncomment specific lines from a file with patterns in oracle linux 8.6 using bash. There are leading white spaces on certain lines where the comments are not removed. I tried to uncomment the commented lines with sed and grep for matching the patterns. I need to exactly match two numbers from the output. There is one word per column(total 2 columns) in the file each with numbers.

Example: column1:pd19_ORA column2:svg38.

I need to uncomment lines inplace with exact match of 19 and 38 without 190,1900 or 019 etc.. excluding lines such as,

column1:pd**19**_ORA column2:svg**37**  
column1:pd**199**_ORA column2:svg**388** 

Code:

sed -n '/\<19\>/,+1p' cmfile|grep '38'|sed -i '/38/s/^#//g' cmfile

Contents of file:

    #pd19_ORA svg38
#pd19_ORA sil38
#pd29_ORA sil37
    

First line is still commented after using sed with inplace but comment of second line is removed.

Output:

    #pd19_ORA svg38
pd19_ORA sil38
#pd29_ORA sil37

How to remove the first line comment which has leading white spaces without removing the leading space?

Expected output:

    pd19_ORA svg38
pd19_ORA sil38
#pd29_ORA sil37

I try to uncomment specific lines from a file with patterns in oracle linux 8.6 using bash. There are leading white spaces on certain lines where the comments are not removed. I tried to uncomment the commented lines with sed and grep for matching the patterns. I need to exactly match two numbers from the output. There is one word per column(total 2 columns) in the file each with numbers.

Example: column1:pd19_ORA column2:svg38.

I need to uncomment lines inplace with exact match of 19 and 38 without 190,1900 or 019 etc.. excluding lines such as,

   #pd19_ORA svg37 
#pd199_ORA svg388 

Code:

sed -n '/\<19\>/,+1p' cmfile|grep '38'|sed -i '/38/s/^#//g' cmfile

Contents of file:

    #pd19_ORA svg38
#pd19_ORA sil38
#pd29_ORA sil37
    

First line is still commented after using sed with inplace but comment of second line is removed.

Output:

    #pd19_ORA svg38
pd19_ORA sil38
#pd29_ORA sil37

How to remove the first line comment which has leading white spaces without removing the leading space?

Expected output:

    pd19_ORA svg38
pd19_ORA sil38
#pd29_ORA sil37
added 369 characters in body
Source Link
Kishan
  • 113
  • 1
  • 6

I try to uncomment specific lines from a file with patterns in oracle linux 8.6 using bash. There are leading white spaces on certain lines where the comments are not removed. I tried to uncomment the commented lines with sed and grep for matching the patterns. I need to exactly match two numbers from the output. There is one word per column(total 2 columns) in the file each with numbers.

Example: column1:pd19_ORA column2:svg38.

I need to uncomment lines inplace with exact match of 19 and 38 without 190,1900 or 019 etc.. excluding lines such as,

column1:pd**19**_ORA column2:svg**37**  
column1:pd**199**_ORA column2:svg**388** 

Code:

sed -n '/\<19\>/,+1p' cmfile|grep '38'|sed -i '/38/s/^#//g' cmfile

Contents of file:

    #pd19_ORA svg38
#pd19_ORA sil38
#pd29_ORA sil37
    

First line is still commented after using sed with inplace but comment of second line is removed.

Output:

    #pd19_ORA svg38
pd19_ORA sil38
#pd29_ORA sil37

How to remove the first line comment which has leading white spaces without removing the leading space?

Expected output:

    pd19_ORA svg38
pd19_ORA sil38
#pd29_ORA sil37

I try to uncomment specific lines from a file with patterns in oracle linux 8.6 using bash. There are leading white spaces on certain lines where the comments are not removed. I tried to uncomment the commented lines with sed and grep for matching the patterns.

sed -n '/\<19\>/,+1p' cmfile|grep '38'|sed -i '/38/s/^#//g' cmfile

Contents of file:

    #pd19_ORA svg38
#pd19_ORA sil38
#pd29_ORA sil37
    

First line is still commented after using sed with inplace but comment of second line is removed.

Output:

    #pd19_ORA svg38
pd19_ORA sil38
#pd29_ORA sil37

How to remove the first line comment which has leading white spaces without removing the leading space?

Expected output:

    pd19_ORA svg38
pd19_ORA sil38
#pd29_ORA sil37

I try to uncomment specific lines from a file with patterns in oracle linux 8.6 using bash. There are leading white spaces on certain lines where the comments are not removed. I tried to uncomment the commented lines with sed and grep for matching the patterns. I need to exactly match two numbers from the output. There is one word per column(total 2 columns) in the file each with numbers.

Example: column1:pd19_ORA column2:svg38.

I need to uncomment lines inplace with exact match of 19 and 38 without 190,1900 or 019 etc.. excluding lines such as,

column1:pd**19**_ORA column2:svg**37**  
column1:pd**199**_ORA column2:svg**388** 

Code:

sed -n '/\<19\>/,+1p' cmfile|grep '38'|sed -i '/38/s/^#//g' cmfile

Contents of file:

    #pd19_ORA svg38
#pd19_ORA sil38
#pd29_ORA sil37
    

First line is still commented after using sed with inplace but comment of second line is removed.

Output:

    #pd19_ORA svg38
pd19_ORA sil38
#pd29_ORA sil37

How to remove the first line comment which has leading white spaces without removing the leading space?

Expected output:

    pd19_ORA svg38
pd19_ORA sil38
#pd29_ORA sil37
edited tags; edited title
Link
ilkkachu
  • 148.1k
  • 16
  • 268
  • 441

Bash Script To Uncomment Lines With Leading Spaces On A File With Specific Patternscript to uncomment lines with leading spaces on a file with specific pattern

Source Link
Kishan
  • 113
  • 1
  • 6
Loading