Is there an easy way to split a field, get the first element from the said split field AND also print other fields in same awk?
I want to modify below such that is works for $2 not just when it's MCU:123 but also when it's DISNEY:654 such that $2 returns MCU or DISNEY depending on the string. Obviously substr was a bad choice there.
MCU:123
DISNEY:654
MCU
DISNEY
awk 'BEGIN{FS=OFS=""}{print $1,substr($2,1,3)}'
Sample of two fields tab seperated
1 mcu:1234 2 disney:234
Expected result tab seperated
1 mcu 2 disney
$ cut -d: -f1 file 1 mcu 2 disney
or if the real file is more convoluted than the example in your question then maybe this will do what you really need:
$ awk -F'[:]' -v OFS='' '{print $1, $2}' file 1 mcu 2 disney
1.4m articles
1.4m replys
5 comments
57.0k users