awk ' {split( $0, a, " " ); asort( a ); for( i = 1; i <= length(a); i++ ) printf( "%s ", a ); printf( "\n" ); }' input >output
Some versions of awk have a buggy asort() function. Off the top of my head I don't remember the circumstanses, but for anything that counts I write my own sort function.
awk: can't open file code.awk
source line number 1 source file code.awk
context is
>>> <<<
I'm not an expert and I'll figure it out if I can, or any advice you can give me? I'll appreciate it. I'll try to install the GNU awk and make the previous code work.
thanks.
For huaihaizi3
Sorry, I'm not an expert and I currently don't know how to run that code you posted, I will definitely research and find out what you mean. I was basically looking for an awk code or a unix command that would do the job. That looks like C, I will work on your code to understand it better and see if I can make it work. I appreciate your help, any advice?
From the looks of things you didn't name the file code.awk. If you run the command ls -al code.awk what do you get? The fact that awk says it cannot open the file means that the file isn't in the current directory.
As for running the other code... edit a file (we'll call it foo.sh just to have something specific) and paste the code into it. Then you can set the execute bit with chmod 755 foo.sh and can run it as a command by typing foo.sh xxx.txt on the command line.
You can do the same with the awk as long as you leave the leading awk ' and trailing close quote.
% ./s1
Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution : Debian GNU/Linux 5.0.8 (lenny)
bash GNU bash 3.2.39
perl 5.10.0
-----
Input data file data1:
4 6 8 1 7
2 12 9 6 10
6 1 14 5 7
-----
Results of single line (cryptic) perl:
1 4 6 7 8
2 6 9 10 12
1 5 6 7 14
I like Scutinizer's solution. It illustrates useful features of perl that are similar to awk features. One does not see them often.
Best wishes ... cheers, drl