• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 326
  • Last Modified:

awk question

Hi all

    I have to extract field 2 from a /etc/shadow file  were the field
Hash filed doesn’t begin with  ($) character  I know how to
Extract the fiel in question bu not when I want to exlude
All the lines were filed 2 begins with $ in the example
Below I want only users 4 5 6

cat /etc/shadow | awk   'BEGIN {FS=":"} {print $1 ,$2}'

user1: $1$fzNYJ5hW$47JQKHHa7uYHH8SqpUwH3/
user2: $1$HjJNobM9$ZHeda26/JYXJlCUgkehW60
user3: $1$XivDPT4M$fHVwDz3UR3cIBfYaEA8jT1
user4:1VI1N2Yi3R3EI:14495::::::
user5:qcD/yKtWISo12:13451::::::
user6:T4oMaMD.tBqOs:11426::::::
0
d_asselin
Asked:
d_asselin
  • 2
  • 2
1 Solution
 
Justin MathewsCommented:
cat /etc/shadow | awk   'BEGIN {FS=":"} index($2, "$") {print $1 ,$2}'
0
 
d_asselinAuthor Commented:
Not there yet

   I need the lines that field $2 doesn’t begin with $
With this line I get all the lines that begin with $

0
 
Justin MathewsCommented:
Sorry,

cat /etc/shadow | awk   'BEGIN {FS=":"} !index($2, "$") {print $1 ,$2}'
0
 
d_asselinAuthor Commented:
This is perfect
 Dan
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now