1

This will delete all spaces and tabs at the beginning of every line:

sed 's/^[ \t]*//' file

but lets say we want to align only the parameter queued.max.requests=1000 from file

  • Example input:
        log.flush.interval.messages=20000
        queued.max.requests = 1000
        producer.purgatory.purge.interval.requests=100
    
  • Desired output:
         log.flush.interval.messages=20000
    queued.max.requests=1000
         producer.purgatory.purge.interval.requests=100
    

How we can fit the sed 's/^[ \t]*//' for this case? Also, I want sed/perl to delete the spaces between the parameter to "=" and from "=" to the value in the process.

1
  • 1
    @Jeff Schaller thank you so much for the update – yael Jul 16 '20 at 13:34
2

How about

sed '/queued\.max\.requests/s/[\t ]\{1,\}//g' file

or

sed -r '/queued\.max\.requests/s/[\t ]+//g' file

This will remove all space (from the beginning of the line, as well as that surrounding the =) from only the line containing queued.max.requests.

0
0
$ sed 's/^[[:space:]]*\(queued\.max\.requests\)/\1/; s/ *= */=/' file
    log.flush.interval.messages=20000
queued.max.requests=1000
    producer.purgatory.purge.interval.requests=100

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.