-1

I need to set the delimiter from a : to three blanks.

So far my code is as follows:

cut -d f1,6,7 test | tr : '   '

Dont mind anything before the pipe, that is just for formatting of the file "test". It will replace the delimiter with one blank, but not three, how do i accomplish this?

hek2mgl
  • 152,036
  • 28
  • 249
  • 266
Mitch
  • 21
  • 1
  • 1
  • 7
  • `tr` is one-to-one replacement. For more than that you need something like `awk` or `sed` or almost anything else. What else have you tried? – Etan Reisner Oct 07 '15 at 18:31
  • 1
    Please specify your requirements in a way that others can follow. In it's current version the question is completely unclear. – hek2mgl Oct 07 '15 at 18:32
  • so i have the following string: larryjohnson:x:604:512: Larry Johnson:/home/students/larryhohnson2:/bin/bash and what i need to do, is extract the user name, home directory, and default shell, so i used this to extract those: cut -d f1,6,7 test, Now i need to replace the : delimiter with three blank spaces, and thats where im stuck, im not sure which awk or sed command to use. – Mitch Oct 07 '15 at 18:35
  • 2
    @Mitch Please edit your question instead of adding the explanation in comments. – hek2mgl Oct 07 '15 at 18:38

1 Answers1

3

This should work:

awk -F: -v OFS="   " '{print $1,$6,$7}' test

-F sets the input field separator to colon, -v sets the output field separator to 3 spaces, then the awk body prints the desired fields

The sed option would be

cut -d: -f1,6,7 test | sed 's/:/   /g'
glenn jackman
  • 238,783
  • 38
  • 220
  • 352