awk question

Posted on 2011-02-16
Last Modified: 2012-05-11
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
Question by:d_asselin
  • 2
  • 2
LVL 16

Expert Comment

ID: 34907970
cat /etc/shadow | awk   'BEGIN {FS=":"} index($2, "$") {print $1 ,$2}'

Author Comment

ID: 34908018
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 $

LVL 16

Accepted Solution

jmatix earned 500 total points
ID: 34908085

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

Author Closing Comment

ID: 34908132
This is perfect

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
count7 challenge 12 100
firstChar challenge 13 106
Arduino EDI - Programming Language - Voice Recorder 4 65
This code tracks birthdays 3 56
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
A short article about a problem I had getting the GPS LocationListener working.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now