LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-18-2017, 01:49 PM   #1
freeroute
Member
 
Registered: Jul 2016
Location: Hungary
Distribution: Debian
Posts: 69

Rep: Reputation: Disabled
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.
 
Old 11-18-2017, 02:41 PM   #2
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 3,064

Rep: Reputation: Disabled
sed can do that if you combine a backreference with greedy mode:
Code:
~$ echo 0123456789 | sed "s/\(.\)./\1/g"
02468
 
2 members found this post helpful.
Old 11-18-2017, 03:51 PM   #3
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 23,932

Rep: Reputation: 7022Reputation: 7022Reputation: 7022Reputation: 7022Reputation: 7022Reputation: 7022Reputation: 7022Reputation: 7022Reputation: 7022Reputation: 7022Reputation: 7022
Quote:
Originally Posted by freeroute View Post
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
I'm seeing a pattern here:
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.
 
Old 11-20-2017, 06:21 PM   #4
freeroute
Member
 
Registered: Jul 2016
Location: Hungary
Distribution: Debian
Posts: 69

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Ser Olmy View Post
sed can do that if you combine a backreference with greedy mode:
Code:
~$ echo 0123456789 | sed "s/\(.\)./\1/g"
02468
Great...Thank you very much for your help.
 
Old 11-20-2017, 07:06 PM   #5
JeremyBoden
Senior Member
 
Registered: Nov 2011
Location: London, UK
Distribution: Debian
Posts: 1,894

Rep: Reputation: 469Reputation: 469Reputation: 469Reputation: 469Reputation: 469
But how would you do it, without using sed?

For example, can the OP do it with a bash script?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] how to add and delete a string in front of a string by sed? Ben Wang Linux - Newbie 6 05-16-2015 06:23 PM
Split string into 2, from 2nd occurance of a character in bash shridhar22 Linux - Newbie 9 07-24-2014 07:19 AM
get value in character string Abid Malik Programming 1 10-23-2010 02:15 AM
Replace 2nd to last Character with SED elproducto Programming 5 03-31-2009 12:41 PM
Shell Script: Delete lines til string found or until particular string. bhargav_crd Linux - General 3 12-20-2007 11:14 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration