You're viewing a comment by karn Kumar and its responses.

karn Kumar Permalink
March 27, 2015, 23:36

Hi ,

I want just Names to be printed from the file using awk , I tried but .. that's not helping to sort it .. pls suggest

#> cat >PP
FFE\Jonny:VAS:1302:99999:aaa:/home/Jonny:/bin/bash
FFE\Mariya:VAS:1304:99999:aaa:/home/Mariya:/bin/bash
FFE\Gammy:VAS:1305:99999:aaa:/home/Gammy:/bin/bash
FFE\Danny:VAS:1310:101:aaa:/home/Danny:/bin/bash
FFE\Tommy:VAS:1314:101:aaa:/home/Tommy:/bin/bash

#> cat PP | nawk -F'[\:]' '{print $1}'
FFE\Jonny
FFE\Mariya
FFE\Gammy
FFE\Danny
FFE\Tommy

Comment Responses

March 28, 2015, 00:22

Here's what you do:

#> cat PP | nawk -F'[\:]' '{print $1}' | nawk -F\\ '{print $2}'
Jonny
Mariya
Gammy
Danny
Tommy

Karn Kumar Permalink
March 28, 2015, 13:35

Hey Peter, Can you explain it.

March 29, 2015, 02:23

There's not much to explain. I simply use nawk twice. The second time I use it I split on \ and print the second field $2, which is the name

cat PP | nawk -F'[\:]' '{print $1}' | nawk -F\\ '{print $2}'
Karn Kumar Permalink
March 29, 2015, 16:16

Thanks Indeed Peter. I am just confusing as being a learner to the nawk caveats ... So, I was thinking that -F'[\:]' will altogether split ":" & "\" at the same time So, we can avoid using nawk twice..

Thanks Indeed.

-Karn

March 31, 2015, 06:26

In that case you'd want to use four backslashes \\\\:

Like this:

cat PP | nawk -F'[\\\\:]' '{print $2}'

Reply To This Comment

(why do I need your e-mail?)

(Your twitter handle, if you have one.)

Type the word "disk_104": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.