How to delete every 2nd character from a string
Is there a way to extract(delete) every 2nd character from a string with command line?
How can I do that? Example: Original string: $826y4$31226$dZbD2JfjeZ3TbIe44M0zclck2O4T1l8j7Y7jfl6maZ2ecU900ObFJk9iz8iCE5AODPQx4QkiQjJOVmG Result : $2y$12$ZDJjZTI4MzlkOTljYjlmZeU0OFJk9iz8iCE5AODPQx4QkiQjJOVmG Deleted(extracted) characters: 864326db2fe3be40cc241877f6a2c90b Other examples:examples Thanks for you help. |
sed can do that if you combine a backreference with greedy mode:
Code:
~$ echo 0123456789 | sed "s/\(.\)./\1/g" |
Quote:
https://www.linuxquestions.org/quest...ex-4175617261/ https://www.linuxquestions.org/quest...rd-4175617127/ https://www.linuxquestions.org/quest...le-4175614474/ https://www.linuxquestions.org/quest...ue-4175613273/ Seems like you've asked many questions like this, and shown no effort of your own when posting, rather just ask for a handout. Can you show us what YOU have done/tried on your own? Can you not apply any of the answers/advice you've been given before and change it to fit your needs? A lot of these sound like verbatim homework questions. Read the LQ Rules and the "Question Guidelines" link in my posting signature. |
Quote:
|
But how would you do it, without using sed?
For example, can the OP do it with a bash script? :) |
All times are GMT -5. The time now is 06:17 PM. |