-1

I have a tab separated text file f.txt like :

APPLE 10 5

BALL 20 6

CAT 30 7

I want the output to be

APPLE_10_5

BALL_20_6

CAT_30_7

I wrote the following to partially accomplish this, but I am stuck at the "paste" step. Can you help?

cat f.txt | cut -f 1,2,3 | paste ???
Ssank
  • 3,367
  • 7
  • 28
  • 34

1 Answers1

0

When the are sperated by one space using sed is a one liner.

sed -i "s/ /_/" input.txt
cb0
  • 8,415
  • 9
  • 52
  • 80
  • There are a couple of problems with this answer: (a) it just replaces the first instance of a space per line (b) it will work with GNU sed only, because of the usage of `-i` without a backup extension (c) useless use of `sed` since `tr` should be used (d) no need to answer a closed question which has been answered already. – hek2mgl Aug 09 '16 at 14:55
  • Thanks for that explanation! I tried but was missing point (b) because of only one whitespace. Btw. I answer before it was closed :) – cb0 Aug 09 '16 at 14:57