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

stuck

  • 06-09-2007 1:52am
    #1
    Closed Accounts Posts: 91 ✭✭


    #!/bin/bash
    echo $1 | cat - $2 >> /tmp/$$ && mv /tmp/$$ $2

    im trying to get the first argument to go in the middle of the second argument which is a file, anyone any ideas.i have only managed to get it to go on the end or the front.

    been fiddling about with wc -l, i get the number of lines but not sure how i use that to insert the argument


Comments

  • Registered Users, Registered Users 2 Posts: 1,064 ✭✭✭Snowbat


    I'm curious why you'd want to add something in the middle of a file but...
    #!/bin/bash
    HALFWAY=$((`cat $2 | wc -l`/2))
    awk "NR <= $HALFWAY" $2 > /tmp/$$
    echo $1 >> /tmp/$$
    awk "NR > $HALFWAY" $2 >> /tmp/$$
    mv /tmp/$$ $2
    


  • Closed Accounts Posts: 91 ✭✭magnia


    cant use awk or seds but what u wrote looks good. trying to learn unix out of a book. this was just one of the questions at the end of a chapter. can it be done with awk or sed.


  • Registered Users, Registered Users 2 Posts: 1,064 ✭✭✭Snowbat


    Even my router has awk and sed available but you could do it this way:
    #!/bin/bash
    HALFWAY=$((`cat $2 | wc -l`/2))
    COUNTER=0
    for i in `cat $2`;
    do
            echo $i >> /tmp/$$
            if [ $COUNTER -eq $HALFWAY ]
            then
                    echo $1 >> /tmp/$$
            fi
            let COUNTER+=1
    done
    mv /tmp/$$ $2
    


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


    tail has an option to specify number of lines. Off the top of my head, it's what I'd use.


Advertisement