How to name a file like users-DDMMYYYY format?

Posted on 2005-04-18
Last Modified: 2013-12-23
How can i write a shell script that extracts all the usernames from the file /etc/passwd into a file /tmp/users-DDMMYYYY, then sorts this file alphabetically into another file /tmp/sortedusers-DDMMYYYY and finally join all the usernames together into a single line, with each username separated by a horinzontal tab (thiswill be display on the screen)? DDMMYYYY refers to the current system date.
Thanks for any help
Question by:anhphuc
    LVL 38

    Accepted Solution

    > extracts all the usernames from the file /etc/passwd into a file /tmp/users-DDMMYYYY
    > sorts this file alphabetically into another file /tmp/sortedusers-DDMMYYYY

    > join all the usernames together into a single line


    awk -F: '{print $1}' /etc/passwd | sort -u > /tmp/sortedusers-`date +%d%m%Y`

    for USERS in /tmp/sortedusers-`date +%d%m%Y`
       echo -e $USERS \\t  >> /tmp/users-`date +%d%m%Y`
    LVL 51

    Assisted Solution

    awk -F: '{print $1}' /etc/passwd | sort -u > /tmp/sortedusers-`date +%d%m%Y`
    tr '\012' '\009' </tmp/sortedusers-`date +%d%m%Y`

    Author Comment

    i've got another solution

    cut -d: -f1 /etc/passwd | sort -u >/tmp/users-'date-+'%d%m%Y'
    tr '\t' '\n'  </tmp/users-'date-+'%d%m%Y'
    LVL 38

    Expert Comment

    Your solution won't work with /tmp/users-'date-+'%d%m%Y'
    It's back quote ` , not '  .
    LVL 51

    Expert Comment

    also take care that your tr syntax works with GNU tr only

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Suggested Solutions

    The DSL Parameters part of this article is valid and can be considered with any brand of internet router and modem (Dlink, 3com, Alcatel, Usrobotics, Parks), by accessing the configuration interface available by the manufacturer eg: …
    If you're not part of the solution, you're part of the problem.   Tips on how to secure IoT devices, even the dumbest ones, so they can't be used as part of a DDoS botnet.  Use PRTG Network Monitor as one of the building blocks, to detect unusual…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    729 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

    19 Experts available now in Live!

    Get 1:1 Help Now