0

I have a configuration file in the following format

#   ra  y   1000000 \x2e\x72\x61\xfd
#   ost y   500000000   \x21\x42\x44\x4e
#   java    y   1000000 \xca\xfe\xba\xbe

This is what I want to do:

  1. Search for ra, ost, java
  2. If there is a tab before and after ra, ost, java, remove the # at the beginning

I am focusing on tab because the configuration file contains other text as well which might have ra, ost, java mentioned but they all will be separated with space before or after them because they would be mentioned in a paragraph and I don't want to uncomment those lines. Hence, I need to look for tab


steeldriver already has answered. The edit is to mention a part of the file I was working on, on request of John Goofy.

The file is like

# Scalpel configuration file
...
# Scalpel can read Foremost 0.69 configuration files, but Scalpel
...
# Real Audio Files
#      ra  y       1000000 \x2e\x72\x61\xfd
# MISCELLANEOUS
#      java        y       1000000 \xca\xfe\xba\xbe
# Outlook files
#      ost y       500000000       \x21\x42\x44\x4e

Although this configuration file didn't mention the list of names of file formats it can work on but if it had mentioned the names like

# Scalpel works on ra ost java

Then the answer steeldriver gave is perfect

2
sed '/^#\t\(ra\|ost\|java\)\t/ s/^#//' file

or (if extended regular expressions are supported) you can avoid some of the escaping

sed -E '/^#\t(ra|ost|java)\t/ s/^#//' file
| improve this answer | |
  • Love you @steeldriver <3. Thank you so much. – GypsyCosmonaut Jul 16 '17 at 13:58
  • What is the different between the the normal regular expressions in first command and extended regular expression in second command? – GypsyCosmonaut Jul 16 '17 at 14:03
  • @steeldriver For both commands on my machine the output is the same like the input. – John Goofy Jul 16 '17 at 14:04
  • @JohnGoofy did you replace any of the spaces in the OP's example by tabs? unfortunately the forum formatting doesn't preserve tabs in pasted input – steeldriver Jul 16 '17 at 14:12
  • @steeldriver I have copied the given input into a file and check the tabs with vim if they are there. – John Goofy Jul 16 '17 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.