LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-14-2010, 04:18 PM   #1
saurin
Member
 
Registered: Aug 2008
Posts: 50

Rep: Reputation: 0
how to remove alternate char from file


How to remove alternate char from file using shell script?
if the file content is "1234567890" the output file should be "24680"

there may be small modification to generate two alternate byte, what it should be?
if the file content is "1234567890" the output file should be "125689"

Last edited by saurin; 01-14-2010 at 11:53 PM.
 
Old 01-14-2010, 04:53 PM   #2
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
It's not even really a script, just a simple one liner.

sed 's/\(.\)\(.\)/\2/g' filename

You could logic it out in bash I suppose using cut, but...
Code:
core:~/test/test26$ echo "1234567890" > filename
core:~/test/test26$ cat filename
1234567890
core:~/test/test26$ sed 's/\(.\)\(.\)/\2/g' filename
24680
core:~/test/test26$
I remember doing some fun things like this back in the 90s to make rudimentary document encryption with the addition of rotX (take each character of a document separate it by a space, fill the spaces with a random character, rotX the entire mess (with a special character set including basic punctuation.) Decryption was simple, could even do it in your head if you knew the trick, but at the time I was pretty impressed with my 'ingenuity'. Kept my programming teacher busy all year

Last edited by rweaver; 01-14-2010 at 05:04 PM.
 
1 members found this post helpful.
  


Reply



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
Menuconfig+load alternate config file option gauravholey Linux - Kernel 1 07-03-2009 01:51 AM
Read First Char from file in C++ ckoniecny Programming 2 09-30-2006 03:43 AM
remove singel char lines Ljohan Programming 4 03-16-2006 04:11 AM
alternate config file for sshd w/ RH EL3 kmitz Linux - Security 1 01-13-2005 04:46 PM
Read a char from a file (PERL) linuxlover1 Programming 4 01-09-2005 09:10 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:09 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