How to on one line awk commands?
-
You can combine the use of sed and awk by using UNIX pipes.
We have our sample data_file
hamster, furry little creature, 2 hamster drive donkey, back breaking helper, 8 donkey jacket road horse, top racer, 12 Horse throat Lane badger, night rider, 15 Badger Close cow, love eating grass all day, 16 Moofield Aveune sheep, can you take this coat off, 6 Wool road
I have simple sed script called sed_script to change road to Road and drive to Drive.
s/ road/ Road/ s/ drive/ Drive/
To combine the two sed & awk, sed makes the changes in the sed script and awk prints the third column, as separated by the comma.
$ sed -f sed_script data_file | awk -F, '{ print $3}' 2 hamster Drive 8 donkey jacket Road 12 Horse throat Lane 15 Badger Close 16 Moofield Aveune 6 Wool Road
© Lightnetics 2024