Scramble characters in AWK
I see I'm finally posting an AWK question rather than an answer for a change :)
I wanted to make an AWK script that would scramble all the characters in each field, but leave the first and last characters where they were. How would I do this? |
Quote:
|
And, by the way, it conceptually is very similar to the ways it can be done in Perl - the same entities are involved. So I'm surprised you are asking it - you have already read Perl documentation on regular expressions, haven't you ?
|
My only hint would be, think of options for what FS can be
|
Quote:
|
Oh, and by the way, starting from the way one would do it with his/her eyes and fingers still applies.
|
MTK358, if I remember correctly, the thing you want to do with 'awk' is very close to what you once wanted to do with Perl - I mean that OO "C" attempt of yours. I think in that case you meant to replace string middle leaving the beginning and the end intact. This time the beginning and the end are just single characters, but other than that it's the same task, isn't it ?
|
Thanks for emotionally spoiling another project for me.
For some reason this makes me so emotional. Is there a way to not have the "View Post" button on ignored posts? And is there a way to have other members write as if no one replied? The mods claim that it will make no difference here: http://www.linuxquestions.org/questi...hreads-799110/ but they are WRONG WRONG WRONG!!! :cry: |
Quote:
Even so, it's not like the manual says how do do this. Oh, I get it. You just want me to look STUPID. |
MTK;
Please count to ten before continuing in this thread. What I see is a terse comment from Sergei, followed by several helpful comments. It would have been much better to respond to the latter. Regardless, do not post anything else here except a discussion of the substance of your problem and the suggestions so far. To discuss anything else, send me a PM or e-mail. thank you |
Ok ... well he seems to be offline now, so do you have any questions I can help with?
Did you understand my hint? |
+1 pixellany to just continuing on the thread topic :)
|
For example:
Quote:
I just asked for an algorithm, or some hints on how to make one. I noticed many times before that he thinks I don't read anything. There is a difference between not reading something and reading something that you have no clue about. It's as if he doesn't understand the concept of not understanding. It also seems to me that he looks down upon me for being stupid for doing something before I fully understand it. But how else do you learn? For example this little comment that really hurt me: Quote:
I am not working in a big corporation setting up a huge corporate server without knowing where log files are. I am sitting relaxed at home at my desktop, setting up a server just for the sake of learning how servers work, without any real intention of serving a public website, and to have a platform to learn PHP on. Also, I find your terse language difficult to understand, and to a certain degree I find it condescending. And one last thing: I just can't stand those cryptic puzzles and weird ways of doing things that so many members disagree on. You are the polar opposite of LQ's fun, helpful atmosphere. So if you want to help me, please understand these concepts first:
If you disagree even slightly, I kindly ask you not to ever reply to my threads again. I would rather not get any replies at all than get a reply from you. |
MTK;
I asked you to keep this to the substance of your question. Because you ignored my request, you have been given a 1-day "time out". Please contact me or any moderator privately to discuss further. |
Not a direct answer to your question, but an alternative:
While it's quite easy in gawk, I wanted to see if I could do it using bash. Here's how I did it: Code:
#!/bin/bash Code:
$ ./scramble this is a test |
I just want to point out RTFM answers are unhelpful.
Sometimes the manual is unclear or not understandable by the poster in which case a explanation followed by a suggestion to look at the manual would be more approate. |
Quote:
Now prove here that neither of the built-in functions and neither of the built-in variables can serve your purpose. I.e. show here that you have read, comprehended and analyzed the text and that the text has no relationship to what you are trying to achieve. Of course, for your purpose you do not need all the built-in functions and all the built-in variables, but but you do need some of them. So, show your process of analysis and selection/discarding. I.e. write here "I think that function/variable FOO is not good for my purpose because ...". Or the opposite. |
Quote:
If/when you describe how you would it with your eyes and fingers, the equivalent functions and variables doing the job are much easier to find. |
Quote:
|
Quote:
In my case it wasn't even in programming, it was in electronics. Imagine a long (2 .. 3m), but very thin (50 mm => 2 inches) in diameter apparatus in special "oven" where it's heated to 125C or higher. It had to be - the apparatus was for oil well logging, the temperatures are high in oil wells. So, the apparatus fails with temperature, and I don't know why. And when temperature goes back down, it functions again normally. To debug it I needed to guess which signals to make accessible, but doing so meant soldering to the nodes long wires (the same 2 .. 3m), and circuits in general do not like long wires. ... So, don't even think of doing anything unless you have a clear plan of debugging. Starting PHP on a WEB server without even thinking where the error messages go (and they go to the server log) is a complete and utter nonsense. Actually, the very first question you have to ask yourself is not "how am I going to do it ?", but rather "how am I going to debug it". Much later in my life I took part in design of a pretty well known chip. Chip signals can often be observed using a tool similar to oscilloscope. So, there was a problem with the chip - its die was attached to the plastic by the signal side. The company had a $$$$$$$ tool to drill the silicon at precise coordinates to precise depth in order to just be able to observe the signals. And the company thought about it before the chip came into physical existence, while the chip was being developed. At all, writing code assuming no mistakes will be made is complete and utter nonsense. There is a whole bunch of posts in this forum from people who have problems which are easily seen through compiler warnings which are disabled. So the people scratch their heads at runtime instead of seeing the problems at compile time. ... So, whenever you have problems of your very special kind, it's because you prefer doing things your special way. |
Quote:
I perfectly well understand the concept of not understanding. In fact, when I read new for me documentation I often do not understand too. But I have learned to slow down in such cases and to clearly formulate what I do not understand. I.e. I'm asking myself: "What is the very first thing I do not understand ?". It really helps - then I focus on that thing and typically find an answer. Sometimes using this approach I actually prove that the document I'm reading is wrong - the item in question is defined after it's used or in a separate document. I saw a number of such problems in PCI Express documentation, for example. And, as I wrote many times, I am doing analysis. I.e. typically the text contains enough details to make a decision to either further study it or to discard it as irrelevant for the answer I'm trying to find. So, MTK358, I most often here see that you don't even start performing the needed analysis. |
Sergei (and everyone);
Please--no more on this. We frown on closing threads but, in this case, let's put this behind this and make a fresh start. |
All times are GMT -5. The time now is 08:21 AM. |