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 10-14-2016, 10:24 AM   #1
freeroute
Member
 
Registered: Jul 2016
Location: Hungary
Distribution: Debian
Posts: 59

Rep: Reputation: Disabled
What is the easiest way to convert this hash format to another format?


Could you help me what the easiest way is to convert these hashes on terminal with commands?

From this format:
oAZkAse75vY3DUyTwXhW*K$wqoWNvN,ae6a26879f684db2737173fecf6b9199ac5ed5ec0d1b66ac9474ec5fb794fc55
3ZIdz2V538b@L36c@Ces%MWKvkyXri,27aa7b56ecf8f93f72961bddc4a121ce4f251dc3a3ece660f351a88d777ec43d

to his format:
ae6a26879f684db2737173fecf6b9199ac5ed5ec0d1b66ac9474ec5fb794fc55AZkAse75vY3DUyTwXhW*K$wqoWNvN
27aa7b56ecf8f93f72961bddc4a121ce4f251dc3a3ece660f351a88d777ec43d:3ZIdz2V538b@L36c@Ces%MWKvkyXri

So the separator will be ":"

Thanks in advance.
 
Old 10-14-2016, 10:31 AM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,147

Rep: Reputation: 887Reputation: 887Reputation: 887Reputation: 887Reputation: 887Reputation: 887Reputation: 887
not sure i am following but maybe man tr will help ?
 
1 members found this post helpful.
Old 10-14-2016, 10:44 AM   #3
freeroute
Member
 
Registered: Jul 2016
Location: Hungary
Distribution: Debian
Posts: 59

Original Poster
Rep: Reputation: Disabled
Thanks. I will try....
 
Old 10-14-2016, 12:38 PM   #4
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Ubuntu, Devuan, OpenBSD
Posts: 2,473
Blog Entries: 3

Rep: Reputation: 1099Reputation: 1099Reputation: 1099Reputation: 1099Reputation: 1099Reputation: 1099Reputation: 1099Reputation: 1099
"tr" will translate or delete characters but not swap blocks of them. "perl" does that easily, but a step simpler is "awk"

Code:
awk 'BEGIN{FS=","; OFS="~"} { print $2, $1 }' < in.txt > out.txt
Look up FS and OFS in the manual page for "awk" for details.
 
1 members found this post helpful.
Old 10-14-2016, 01:06 PM   #5
273
LQ Addict
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 6,799

Rep: Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945
Sorry, could somebody please explain to me how one can convert the output of one has routine to another? Or is this a mark-up problem?
 
Old 10-14-2016, 01:35 PM   #6
freeroute
Member
 
Registered: Jul 2016
Location: Hungary
Distribution: Debian
Posts: 59

Original Poster
Rep: Reputation: Disabled
@Turbocapitalist

Thank you for your help.
It works....
 
Old 10-14-2016, 01:40 PM   #7
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Ubuntu, Devuan, OpenBSD
Posts: 2,473
Blog Entries: 3

Rep: Reputation: 1099Reputation: 1099Reputation: 1099Reputation: 1099Reputation: 1099Reputation: 1099Reputation: 1099Reputation: 1099
You're welcome. The important thing is that "awk" becomes more familiar. It will over time. What did you think of the "awk" manual page regarding FS and OFS? And about $1 and $2 and how they relate to FS and OFS?

Code:
man awk
 
1 members found this post helpful.
Old 10-15-2016, 08:18 AM   #8
freeroute
Member
 
Registered: Jul 2016
Location: Hungary
Distribution: Debian
Posts: 59

Original Poster
Rep: Reputation: Disabled
Thanks. I like awk. FS= file separator of input data, OFS= file separator of output data, changing FS to OFS. Is it correct?

I got another tip:
sed -n "s/\(.*\),\([a-f0-9]*\)/\2:\1/p" input.txt >> output.txt

What is the difference between awk and sed?
I know tr, uniq, sort, cat, tac and other easy commands. awk and sed more complex....But until this time I didn't need these commands. So which is the most familar? Which is easier to learn?
 
Old 10-15-2016, 09:02 AM   #9
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,544

Rep: Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898
Not a case of easiest to learn but rather right tool for the job.

Here is sed manual / tutorial to help compare :- http://www.grymoire.com/Unix/Sed.html
 
2 members found this post helpful.
Old 10-15-2016, 09:06 AM   #10
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Ubuntu, Devuan, OpenBSD
Posts: 2,473
Blog Entries: 3

Rep: Reputation: 1099Reputation: 1099Reputation: 1099Reputation: 1099Reputation: 1099Reputation: 1099Reputation: 1099Reputation: 1099
They each lend themselves to somewhat different tasks. It's useful to find what you find each is good for and then use them for that. There is often an optimal zone where a task will lend itself more to one than another. So it's more of the idea of the right tool for the job. As to what is more familiar, that depends on which one you use most. For me it is "perl". You should find all three on any system you encounter. They're all pretty easy to get the hang of, again the one you use most will become most familiar and thus easiest.

One thing to remember is maintainability and much of that depends on code that clear to understand. You can do weird or overly clever things in "sed" that might be easier for another person to follow if you use "awk". Same for "perl" over "awk". But anyone can write clear or unclear code in most any language, since a good portion of that choice is up to the coder. Make the computer do the work. That's what it's for.
 
1 members found this post helpful.
  


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
How to convert an MD5 hash into shadow format SentralOrigin Linux - Software 1 11-28-2010 09:11 PM
[SOLVED] Simple Linux script to convert datetime format to UTC format shayno90 Linux - Newbie 10 10-09-2009 08:19 AM
How to convert rm format music files to mp3 format me4linux Linux - Software 2 05-15-2007 01:45 PM
Whats the easiest way to format Jmcatch742 Linux - General 12 01-08-2005 01:31 PM
use vi to convert linux format to windows format intolinux Linux - Software 2 12-10-2003 10:20 PM

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

All times are GMT -5. The time now is 06:57 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration