Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then 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.
Hi there
I'm new to this forum:
I was wondering if someone could help me figure out a task
In the second field, change 'f' to female and 'm' to male globally. Display the first 9 lines.
Use 2 sed statements one piped to another.
Note use of single quotes in examples.
This was my output
[sjim7@hills ~]$ grep -k2 |sed 's/m/male/g' famous.data | sed 's/f/female/g' | head -n 9
grep: invalid option -- 'k'
Usage: grep [OPTION]... PATTERN [FILE]...
Try `grep --help' for more information.
01 male maleotzart amaleadeous 25 2nd 94233
02 male guthrie woody 23 2nd 94223
03 female simaleone nina 27 2nd 94112
04 male lennon john 29 2nd 94221
05 female harris emalemaleylou 20 2nd 94222
06 male malearley bob 22 2nd 94112
07 female malearley rita 26 2nd 94212
08 female warwick dione 26 2nd 94222
09 male prine john 35 3rd 94321
How would i type it to focus on the second column to change the m to males, and f to females , instead of changing every letter in each column that has a m to male , thanks
grep -k2 at the beginning has no effect at all, and also it does not work (grep: invalid option -- 'k')
You would also need to understand the g at the and of the sed commands, probably that should be changed. Also you can use only one sed command instead of two invocations. You can try awk also, if it was more convenient for you.
grep -k2 at the beginning has no effect at all, and also it does not work (grep: invalid option -- 'k')
You would also need to understand the g at the and of the sed commands, probably that should be changed. Also you can use only one sed command instead of two invocations. You can try awk also, if it was more convenient for you.
would you be able to do it in awk ?
im not sure how to do it in awk, i was trying to see if i could use a sort function on the command line im currently using to only change the 2nd column m to males. To change all the m to male and f to female, without having all the other m's in different columns switch to male too
---------- Post added 10-11-12 at 12:59 AM ----------
Yes, I can do it using awk, perl, sed, c or probably only bash, that is not a problem. But I would rather see you can do it yourself.
Can you explain how did you find the original command you tried?
I'm trying to only search for the m/f so i can change the m to male and f to female in column 2 only
Can you please help me, I've been trying to figure this out for 2 days already !!
and this is the output i get
01 male maleotzart amaleadeous 25 2nd 94233
02 male guthrie woody 23 2nd 94223
03 female simaleone nina 27 2nd 94112
04 male lennon john 29 2nd 94221
05 female harris emalemaleylou 20 2nd 94222
06 male malearley bob 22 2nd 94112
07 female malearley rita 26 2nd 94212
08 female warwick dione 26 2nd 94222
09 male prine john 35 3rd 94321
its suppose to be this :
01 male motzart amadeous 25 2nd 94233
02 male guthrie woody 23 2nd 94223
03 female simone nina 27 2nd 94112
04 male lennon john 29 2nd 94221
05 female harris emmylou 20 2nd 94222
06 male marley bob 22 2nd 94112
07 female marley rita 26 2nd 94212
08 female warwick dione 26 2nd 94222
09 male prine john 35 3rd 94321
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.