list file by column
I have a file , the content is as below , the character is separated by space ,
file content ============ aa bb cc dd dd ff " " can advise if I want to list it by column as below . column 1 ============ aa dd column 2 ============ bb dd column 3 ============ cc ff what can i do ? thx |
I dont really understand your question, and it is difficult to give an example when you only gave two lines of sample data.
But i think sort will be the solution to your needs, I replicated the pattern in your examples further down the alphabet for a clearer example. "man sort" for info on what criteria you want to sort by. Code:
$ echo -e "aa bb cc\ndd dd ff\ntt uu vv\nww ww xx" | sort |
***Please use [code][/code] tags around your code and data, to preserve formatting and to improve readability. Please do not use quote tags, colors, or other fancy formatting.***
(934 posts and still posting data raw? Doesn't anyone know what code tags are anymore? :rolleyes: ) As fukawi1 said, more details are in order. But if you want to do it all in one operation you'll probably have to write an awk script. I will probably involve storing fields in arrays and printing them out again at the end or something. Here are a few useful awk references: http://www.grymoire.com/Unix/Awk.html http://www.gnu.org/software/gawk/man...ode/index.html http://www.pement.org/awk/awk1line.txt http://www.catonmat.net/blog/awk-one...ined-part-one/ Printin a single column only though is easy; just use cut: Code:
cut -d " " -f 1 infile |
Probably not what you want, but this is an alternative that does not consider field delimiters.
Code:
bash-4.2$ echo -e "aa bb cc\ndd dd ff\ntt uu vv\nww ww xx" | sort | colrm 3 8 |
Quote:
but it seems not fit my requirement , may be my question is not clear I give another example , my file is as like the crontab file 00 15 * 8 * /bin/chmod 755 /tmp 00 17,20 * 9 1 /bin/runcron " " what I want is to sort it by delimiter , the delimiter is space , I have upload my desired output as attachment , can advise what can i do ? thx |
1 Attachment(s)
please see the attachment
|
Your output.txt file simply shows the fields separated by tab characters rather than spaces.
You could use the 'tr' command to convert spaces to tabs. e.g. cat <file> | tr "[:space:]" "\t" |
Just looking at the original sample, and output....
Code:
$ cat ust Cheers, Tink |
Quote:
it works , may I ask what is the use of tr ? is it used to remove the delimiter - space ? |
|
one more request , if I want to seperate the first 5 column by delimiter , not the whole file , what can i do ? thx
|
Quote:
Quote:
Quote:
Not only did you mislead the forum by posting irrelevant crap as sample data. The irrelevant crap wasn't even close (alpha rather than numeric) to the same format of the REAL data you wanted answers for.. I guess, luckily for you, the rest of the LQ community is somewhat more tolerant of stupidity than I am. |
Quote:
I am not intended to mislead the forum by re-post the requirement , but after I use it , there have a problem , so I ask for help again . |
hi all,
as my previous , if I want to seperate the first 5 column not the shole file ( eg . the first 5 column of a crontab file is data / time ) , cam advise what can i do ? thx |
I am assuming that you want a formatted display of a crontab file. It is much easier to help when good examples of input file format and desired output file format are supplied. It is also more likely that you will get help when you demonstrate some application to the task, such as reading manual pages, writing posts carefully with attention to spelling and use of proper language rather than text messaging abbreviations.
I show a file ust.txt containing this data Quote:
Code:
#!/bin/bash |
All times are GMT -5. The time now is 02:26 PM. |