#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    23
    Rep Power
    0

    Printing data to another file


    Hi guys,

    i need to print the content of the file in another file along with word count.

    for eg
    file 1
    1.txt
    2.txt

    i used
    for i in `cat file`
    do
    cat $i|wc -l > file1.txt
    done

    but i required

    file1.txt to be:

    1.txt - 10
    2.txt - 30
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    Usually Japan when not on contract
    Posts
    240
    Rep Power
    11
    You probably want a loop centered around something like this:
    bash Code:
    read -a FOO <<< $(wc -w $filename)
    echo "${FOO[1]} - ${FOO[0]}"

    The awk solution is more straightforward, but it sounds like you're doing a class assignment centered round the shell. I recommend you investigate why this works before your instructor asks you.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    23
    Rep Power
    0
    thanks dude it worked

IMN logo majestic logo threadwatch logo seochat tools logo