Find the answer to your Linux question:
Results 1 to 6 of 6
Hi, I have a unix test for a job interview and 2 of the pre-test questions [for revision] I have been given, I don't quite understand!!! ...The questions are: 1. ...
  1. #1
    Just Joined!
    Join Date
    Nov 2005
    Location
    Bristol UK
    Posts
    15

    WHich command?

    Hi, I have a unix test for a job interview and 2 of the pre-test questions [for revision] I have been given, I don't quite understand!!! ...The questions are:

    1. Give a command to change all occurances of wordA to wordB for all files in a directory.

    2. Give a command to count the number of lines matching a specified word in a file.

    I thought I knew most of the basic UNIX commands, but have never ever come across such a situation when I would have to use either of these! ...Anyone have any ideas? thanks.

  2. #2
    Linux Engineer Kieren's Avatar
    Join Date
    Aug 2007
    Location
    England
    Posts
    845
    I think number 1 would be 'sed'

  3. #3
    Linux Guru
    Join Date
    Nov 2004
    Posts
    6,110
    grep -c will count words found.

  4. #4
    Linux User cyberinstru's Avatar
    Join Date
    Jan 2007
    Location
    India
    Posts
    362
    For replacing wordA to wordB


    1. perl -p -i -e s/wordA/wordB/g `find .`
    ---------------------------------
    Registered Linux User #440311
    HI2ARUN _AT_ GMAIL _DOT_ COM
    ---------------------------------

  5. #5
    Linux Engineer Kieren's Avatar
    Join Date
    Aug 2007
    Location
    England
    Posts
    845
    Problem with that is it will require Perl to be installed

  6. #6
    Linux Engineer
    Join Date
    Nov 2004
    Location
    Ft. Polk, LA
    Posts
    796
    sed, or even awk, will do it nicely, check the man or info pages to see how to use them

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...