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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
10-14-2016, 10:24 AM
|
#1
|
Member
Registered: Jul 2016
Location: Hungary
Distribution: Debian
Posts: 69
Rep: 
|
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:
ae6a26879f684db2737173fecf6b9199ac5ed5ec0d1b66ac9474ec5fb794fc55  AZkAse75vY3DUyTwXhW*K$wqoWNvN
27aa7b56ecf8f93f72961bddc4a121ce4f251dc3a3ece660f351a88d777ec43d:3ZIdz2V538b@L36c@Ces%MWKvkyXri
So the separator will be ":"
Thanks in advance.
|
|
|
10-14-2016, 10:31 AM
|
#2
|
LQ Guru
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,326
|
not sure i am following but maybe man tr will help ?
|
|
1 members found this post helpful.
|
10-14-2016, 10:44 AM
|
#3
|
Member
Registered: Jul 2016
Location: Hungary
Distribution: Debian
Posts: 69
Original Poster
Rep: 
|
Thanks. I will try....
|
|
|
10-14-2016, 12:38 PM
|
#4
|
LQ Guru
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,756
|
"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.
|
10-14-2016, 01:06 PM
|
#5
|
LQ Addict
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,680
|
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?
|
|
|
10-14-2016, 01:35 PM
|
#6
|
Member
Registered: Jul 2016
Location: Hungary
Distribution: Debian
Posts: 69
Original Poster
Rep: 
|
@Turbocapitalist
Thank you for your help.
It works.... 
|
|
|
10-14-2016, 01:40 PM
|
#7
|
LQ Guru
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,756
|
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?
|
|
1 members found this post helpful.
|
10-15-2016, 08:18 AM
|
#8
|
Member
Registered: Jul 2016
Location: Hungary
Distribution: Debian
Posts: 69
Original Poster
Rep: 
|
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?
|
|
|
10-15-2016, 09:02 AM
|
#9
|
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Arch
Posts: 10,037
|
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.
|
10-15-2016, 09:06 AM
|
#10
|
LQ Guru
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,756
|
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.
|
All times are GMT -5. The time now is 10:39 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|