![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Korn: How to zero fill df output so it will sort properly | shew01 | Shell Programming and Scripting | 9 | 06-04-2008 11:34 AM |
| how to arrange 3 file to one using awk...? | penyu | Shell Programming and Scripting | 9 | 01-17-2008 05:26 AM |
| sort output | funksen | Shell Programming and Scripting | 9 | 01-14-2008 04:40 AM |
| Sort - only one field appears in output? | miwinter | UNIX for Dummies Questions & Answers | 1 | 07-24-2006 11:47 AM |
| re arrange the columns | ahmedwaseem2000 | Shell Programming and Scripting | 0 | 09-23-2005 03:51 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
how to sort and arrange an output
ok so I have a list of names that end in either ot,om,oa.
So for example DETOT MANOA DET0M DET0A MANOT SEAOT etc... I want to be able to group this list by OT, OM, OA and have the output have some headers like this and be alphabatized and if possible be in colums instead of like below so three columns: OT ----- DETOT MANOT SEAOT OA ---- DETOA MAN0A Thanks for any feedback! |
|
||||
|
Thank you for the reply. Actually it will always be 5 charectors and it's all the letter O not zero's......
Is your scenerio still the best way? How do I column it out? i'm assuming some printf command but again I'm so new I'm not familiar on how to use it. |
|
|||||
|
Quote:
Code:
#!/bin/sh
MYGROUPS="OT OM OA"
file_to_sort=$1
for group in $MYGROUPS
do
echo "$group"
echo "--"
egrep "${group}\$" $file_to_sort | sort
echo ""
done
# Catch any unexpected input (if you want that)
if egrep -v "`echo $MYGROUPS | sed 's/ /\|/g'`" $file_to_sort > /dev/null
then
echo "*** UNEXPECTED ***"
egrep -v "(`echo $MYGROUPS | sed 's/ /\|/g'`)" $file_to_sort
fi
|
|
||||
|
Ok i'm really really new to this is there anyway you can break down your post?
This is what I understand. is to echo each group and put a -- under it then search for each group (OT OM OA) and I kinda get lost here .... I'm so sorry that I need so much help! by the way I did test it and it worked out perfect!!! Is there a way to make the outputs be side by side columns? Also how can I change the headings of the groups? So I want to still group by OT OM OA but I want the headings of each to be something different? Last edited by llsmr777; 11-12-2007 at 05:48 PM.. |
|
|||||
|
Side by side is harder as you'd have to either make temporary files or store the lists in memory, then display it back out once you are ready.
Shell doesn't lend itself very well to formatting output, you'd have to monkey about with inserting a number of tab characters based on how long the various names in the file are. Perl would probably be the language of choice for this as it's got a very nice function for generating reports etc called 'format'. You can design a form, then populate the data and dump it out via the 'write' command. It'd be a bit more complex than the previous shell script though as it would also need to store things in memory or in files rather than streaming everything. |
![]() |
| Bookmarks |
| Tags |
| regex, regular expressions |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|