Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi all! We have been experiencing an issue on site where threads have been missing the latest postings. The platform host Vanilla are working on this issue. A workaround that has been used by some is to navigate back from 1 to 10+ pages to re-sync the thread and this will then show the latest posts. Thanks, Mike.
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

counting words then amending to a file

  • 11-09-2007 12:11am
    #1
    Closed Accounts Posts: 91 ✭✭


    i want to count the number of words in a file and then redirect this to a file


    echo 'total number of words=' wc -users>file


    THis isnt working, anyone any ideas.


Comments

  • Registered Users, Registered Users 2 Posts: 1,636 ✭✭✭henbane


    Wouldn't the dash cause a problem? 'man wc' is very useful in these situations


  • Registered Users, Registered Users 2 Posts: 125 ✭✭ceidefields


    echo "total number of words=" > test.log; wc -w names.log >> test.log

    I think that's what you want - test.log is your output file. Names.log is the file you're counting words in.


  • Registered Users, Registered Users 2 Posts: 37,485 ✭✭✭✭Khannie


    Do me a favour please....just keep all your questions to one thread? You have 4 on the go now.


  • Registered Users, Registered Users 2 Posts: 2,747 ✭✭✭niallb


    echo 'total number of words='$(cat /tmp/yourinputfile \
    | wc -w ) | tee /tmpyouroutputfile
    
    This contains a number of constructions that would be useful in similar exercises.
    I also agree with Khannie that you should keep these on one thread.

    tee is handy when debugging as you can easily keep track of a number of outputs and it saves you having to open the output file to see if anything happened.

    It's also a really useful trick for writing out to a root owned file from a
    process run by your user account under ubuntu/OSX or similar.
    [b]sudo[/b] arp -an | awk ' { print $4"\t "$2 } ' | tr -d \(\) \
    | grep -v incomplete [b]>>/etc/ethers[/b] [i]won't work[/i]
    
    arp -an | awk ' { print $4"\t "$2 } ' | tr -d \(\) \
    | grep -v incomplete [b] | sudo tee -a /etc/ethers[/b] [i]will[/i]
    

    If by amending you really mean appending you can find the
    right flag using man tee or as you know, just use >>.
    You need to be more careful with how you phrase your questions,
    to make sure they're what you really want.
    You unix shell will do exactly what you tell it to do, and it will
    be much less forgiving of your attention to spelling and punctuation than this forum.
    cd /tmp ; rm -rf * is very different to
    cd / tmp ; rm -rf *
    It's only a space, but it'll give you a lot of space on your drive,
    or on the drive of your new employers database server for example if you miss it.

    You're asking good questions here, and I'm sure a lot of people are enjoying
    seeing them answered. It would be good though if you posted up your final scripts so that everyone can see the finished article.

    How did you get on in the job interview a few weeks ago?
    Did you get the first batch of scripts in on time?
    Ideally, you shouldn't be learning unix for an interview, but for the job itself.
    Are you confident that if you get the position you'll be able to learn on the job quickly enough to be useful?

    How confident are you that your prospective employer isn't one of us :-)
    That need not be a bad thing. The most important single ability a Unix user and
    particularly an admin can have is knowing where to look for help and how to ask
    for it. This forum is quite suitable for what you're asking.

    Finally, take a read of the "Advanced Bash Scripting Guide". Realising that
    you only need know a tenth of it to be really useful will take the edge off it!
    Having an idea of what else is possible though is important, and nobody writes
    scripts using structures they themselves use rarely without looking up syntax
    or flags.

    Good luck with it,
    NiallB


  • Registered Users, Registered Users 2 Posts: 37,485 ✭✭✭✭Khannie


    Great post Niallb. Fitting that it's your 1000th. :)

    Edit: Holy crap. I just hit 5000 with that one. :D


  • Advertisement
Advertisement