Find the answer to your Linux question:
Results 1 to 3 of 3
Hi.I need to do a script that can receive any number of parameters which are file names and return the number of lines every file has.the output should be like ...
  1. #1
    Just Joined!
    Join Date
    Dec 2009
    Posts
    2

    Shell scripting wc usage

    Hi.I need to do a script that can receive any number of parameters which are file names and return the number of lines every file has.the output should be like that "The file nameoffile.txt has 5 lines".From what i have done my output is like "The file nameoffile.txt has 5 nameoffiletxt lines".how can I do the output without printing the name of file after the number of lines.thanks

  2. #2
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    do your own homework first. what have you tried

  3. #3
    Just Joined!
    Join Date
    Dec 2009
    Posts
    2
    Here is what I've writen in my script :
    #!/bin/bash
    for i in $@;do
    echo "The file $i has $(wc -l $i) lines"
    done


    It works but I don't want to display the name of file after the number of lines.

Posting Permissions

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