ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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'm having problem's with the output of awk I have a few things to say first ill show the database file layout
FILE :
#Groupname; Lastname, Firstname
*******************************
amotet; Tetzlaff, Nicholas
lavlym; Lavallie, Stacey Anne
lawzuz; Zuzarte, Mark W
lawzuz; Lawrence Leger, Daniel Thomas
leusom; Somji, Rahim
leusom; Leung, Hoi-yung Gary
lavlym; Lymberis, Andrew John
NEEDED OUTPUT:
Team Member ---------------------------------------- Group Name
=========================================
Stacey Anne Lavallie -------------------------------------lavlym
Andrew John Lymberis-----------------------------------lavlym
-- suppose to be white space
I have the user input the groupname they would like to see the members for this i just input the string manually
I'm having Problems with the spacing
sed 's/,/;/g' teamlist.dat > test
awk 'FS=";" {if ($1 ~/lavlym/ && NR > 2) print $3, $2, $1}' test
outputs this
Team Member ---------------------------------------- Group Name
=========================================
Stacey Lavallie lavlym
Andrew Lymberis lavlym
it chops off there middle name but is I only display $3 it show first and middle like its suppose to
If anyone can point me in the right direction I would greatly appreciate it
Thanks
awk ' { print $3, $4, $2, ": ", $1}' teamlist.dat | sed -e 's/, //' -e 's/;//'
Firstname Lastname: #Groupname
: *******************************
Nicholas Tetzlaff: amotet
Stacey Anne Lavallie: lavlym
Mark W Zuzarte: lawzuz
LegerDaniel Lawrence : lawzuz
Rahim Somji: leusom
Hoi-yung Gary Leung: leusom
Andrew John Lymberis: lavlym
1. As you're quickly discovering, tools like "awk" and "sed" work best when
your data format is simple; they become much more difficult when there are
a lot of "exceptions to the rule".
If you don't have a really, really simple data format, you're often much better
off writing in some other tool (Perl, for example, or C). Please consider if this
project might be better done in Perl than in "awk".
2. Having said that, the key to solving this problem in "awk" is to "simplify" the
format. We have three fields ("group", "last name" and "first name"). If we
reduce things to just one delimiter, then it doesn't matter whether a "last name"
has one, two, three or more words - it all becomes a single field.
For example:
sed 's/;/,/' teamlist.dat \
| awk -F',' '{ printf "%s%s %-10s\n", $3, $2, $1 }' # Parse/format the line
Thanks, that helps better, I would use something different but it is a school assignment for shell scripting course, which we use bash mostly so kinda stuck with what I have thanks for all your input though
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.