Computing.Net > Forums > Unix > another awk question

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

another awk question

Reply to Message Icon

Name: narsman
Date: January 28, 2005 at 11:46:18 Pacific
OS: Windows NT
CPU/Ram: 2.0Ghz 512mb RAM
Comment:

Suppose you have this table:

/home% cat file1
6 fish salmon 1abc1
4 bird parrot 1abc2
9 dog boxer 1abc3
5 insect ant 1abc4

What I need to do is to replace all field 4 with the word "pet" then a dash (-) the the number that appears on field 1. The output should be:


6 fish salmon pet-6
4 bird parrot pet-4
9 dog boxer pet-9
5 insect ant pet-5

Thanks!

~narsman



Sponsored Link
Ads by Google

Response Number 1
Name: LANkrypt0
Date: January 28, 2005 at 12:47:21 Pacific
Reply:

This works fine for me:
$ awk '{print $1" "$2" "$3" pet-"$1}'<file1
6 fish salmon pet-6
4 bird parrot pet-4
9 dog boxer pet-9
5 insect ant pet-5


0

Response Number 2
Name: narsman
Date: January 28, 2005 at 12:58:19 Pacific
Reply:

LANkrypt0,

Thanks! This worked quite well.

~narsman


0

Response Number 3
Name: vgersh99
Date: January 28, 2005 at 13:00:24 Pacific
Reply:

nawk '{$NF = "pet-" $1}1' file1

vlad
#include<disclaimer.h>


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: another awk question

awk question www.computing.net/answers/unix/awk-question/6685.html

AWK Question www.computing.net/answers/unix/awk-question/4512.html

sed awk question www.computing.net/answers/unix/sed-awk-question/6900.html