Linux - NewbieThis 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.
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.
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
aa bb cc
dd dd ff
tt uu vv
ww ww xx
***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? )
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.
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
aa bb cc
dd dd ff
tt uu vv
ww ww xx
thx reply ,
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
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"
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"
thx reply,
it works ,
may I ask what is the use of tr ? is it used to remove the delimiter - space ?
Well, in my defense, I never stood a bloody chance...
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.
Well, in my defense, I never stood a bloody chance...
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.
thx r suggetion ,
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 .
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 ?
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
Despite my reservations about this being a homework assignment, here is a bash script that seems to do what you want.
Code:
#!/bin/bash
while read -a line; do
echo -n ${line}
for (( i=1; i<${#line[*]}; i++ )); do
if [[ $i < 5 ]]; then
echo -ne "\t"${line[$i]};
else
echo -n " "${line[$i]};
fi
done
echo
done < ust.txt
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.