run command against txt file

marka01

New Member
Joined
Jan 29, 2021
Messages
4
Reaction score
0
Credits
30
hi, how do I run i.e. "cat /etc/passwd" against all lines in txt file(those are users) and get output on the screen?

thank you
 


Code:
cat /etc/passwd | cut -d ":" -f1
or
Code:
awk -F: '{ print $1 }' /etc/passwd
 
Last edited:
You want to send the output to a file?
Code:
cat /etc/passwd | cut -d ":" -f1 > file1.txt
awk -F: '{ print $1 }' /etc/passwd > file2.txt
 
Sorry I think I formulated my question really badly.. I have txt file with about 1000 lines with user names. What I want is to run this command against each user in txt file:
cat /etc/passwd | grep user

and get output on a screen or to another txt file
 
Can you give an example of what you would like to see and you want all the users in a different text file?
 
Can you give an example of what you would like to see and you want all the users in a different text file?

I have txt with user1,user2,user3..etc (in lines). I want to run 'cat /etc/passwd | grep user. And get this output for each user in TXT file. Does it make sense ?
 
Do you want all the information per user in a file? I think you want something like this?
Code:
#!/bin/bash

mkdir users

for user in $(awk -F: '{ print $1 }' /etc/passwd)
    do
        grep $user /etc/passwd > users/$user.txt
    done
 

Members online


Top