-1

I need to parse the /etc/passwd file in the most efficient way I know I can use the command cat /etc/passwd | awk -F: '{print $1}' but it gets everything in the row, how can I narrow the column so it only gets one input?

I can also make an output file for every row and read from that but that seems like it is ineffective.

edit: so for example, I only need one username from the /etc/passwd file as

user: x 
gid: y
tripleee
  • 175,061
  • 34
  • 275
  • 318
Joe
  • 1
  • 2
  • Please rephrase the question. It is very difficult to understand at the moment. – sjsam Apr 03 '19 at 08:16
  • This sounds like the program worked exactly as it should but you did something else wrong. Did you by any chance capture the output to a variable and then `echo` it without quoting it? – tripleee Apr 03 '19 at 08:58
  • When editing, please take care to not undo useful edits by others. And this is still quite unclear. If you only want one user name, which one? Just the first one? – tripleee Apr 03 '19 at 09:15
  • `awk -F : 'NR == 1 { print "user: " $1; print "gid: " $3 }' /etc/passwd` – tripleee Apr 03 '19 at 09:19
  • Are you sure you have the write permissions for file etc/passwd...or did you mount the root partition as writable? Please tell us exactly what Linux system you’re running! – Kailin Liu Apr 03 '19 at 10:15

1 Answers1

0

It's not quite clear what kind of parsing you want to do, but perhaps cut is the command you're looking for. For example, if you want to get all the usernames and homes you could do this:

cut -d: -f1,6 /etc/passwd

Check the cut man page for more details.

Alex
  • 101
  • 6