I am trying to remove a pattern from all lines in a file. The pattern is 'id': None
and the 3 sed
commands have not worked (the first and third execute but print the file unchanged) and I am not sure if it is the space in the pattern or that 'id':
can appear multiple times. Thank you :).
file
{'version': '1a', 'chr': '17', 'id': None, 'xref_json': None}, 'id': 'This has text in it and this line is printed', 'end': 460}
{'version': '1a', 'chr': '17', 'id': None, 'xref_json': None}
desired
{'version': '1a', 'chr': '17', 'xref_json': None}, 'id': 'This has text in it and this line is printed', 'end': 460}
{'version': '1a', 'chr': '17', 'xref_json': None}
sed
sed '/'id': None,/'d file
sed 's/'id':[[:space:]]None,/ file
sed 's/'id': None,//' file
>Solution :
You may use this sed
:
sed -E "s/'id': *None, *//" file
{'version': '1a', 'chr': '17', 'xref_json': None}, 'id': 'This has text in it and this line is printed', 'end': 460}
{'version': '1a', 'chr': '17', 'xref_json': None}
s/'id': *None, *//
searches for pattern 'id':<0 or more spaces>None,<0 or more spaces>
and replaces that with empty string.