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

Append a line of text to the end of the previous line

  • 11-12-2008 6:05pm
    #1
    Registered Users Posts: 37


    I need to append a line of text to the end of the previous line. My data is as follows:

    dev hostname user user01 show
    * deviceid:6d41fc
    OK
    dev hostname user user02 show
    * deviceid:d8c18e
    OK
    dev hostname user user03 show
    * deviceid:abd00d
    OK

    I need it in the following format and there are a few thousand lines of it:

    dev hostname user user01 show * deviceid:6d41fc
    OK
    dev hostname user user02 show * deviceid:d8c18e
    OK
    dev hostname user user03 show * deviceid:abd00d
    OK

    or even better:

    dev hostname user user01 show * deviceid:6d41fc
    dev hostname user user02 show * deviceid:d8c18e
    dev hostname user user03 show * deviceid:abd00d

    Can anyone help with this?


Comments

  • Registered Users, Registered Users 2 Posts: 3,568 ✭✭✭ethernet


    I suppose you could use this data as a source file and write a script to pull bits from it, perhaps using cut and specifying a space as the delimiter before dumping to another file (or standard output). Don't know of any fancy shortcuts for this but one of the gurus will probably have one.


  • Registered Users, Registered Users 2 Posts: 23,212 ✭✭✭✭Tom Dunne


    I don't follow what you are trying to do.

    Are you Reading from one file, outputting to another?


  • Registered Users Posts: 37 market_garden


    Hi Tom,
    I have a text file containing the following:

    dev hostname user user01 show
    * deviceid:6d41fc
    OK
    dev hostname user user02 show
    * deviceid:d8c18e
    OK
    dev hostname user user03 show
    * deviceid:abd00d
    OK
    .
    . and so on.

    I want to either rearrange the text in the file or read the file and output to another so long as I can get the information in the following format:

    dev hostname user user01 show * deviceid:6d41fc
    dev hostname user user02 show * deviceid:d8c18e
    dev hostname user user03 show * deviceid:abd00d


  • Registered Users, Registered Users 2 Posts: 23,212 ✭✭✭✭Tom Dunne


    I see.

    The best approach would be to read in the source file, do the search, and write it out to a second file.

    So, you would have a loop that does the following:

    look for a string, starting with "dev" and ending with "show" -> first piece
    then look for a string "*" -> second piece
    then search for "deviceid" and continue on for seven characters (to catch the : and the hex number) -> third piece

    I assume you don't want the "OK", so you can ignore that.

    Then you combine the three pieces from above, and write them out to a file as one line.

    Perl would be your man here, regular expressions are what you are looking for. :)


  • Registered Users, Registered Users 2 Posts: 1,823 ✭✭✭EvilMonkey


    cut or awk could also be what your loking for. look at the man page


  • Advertisement
  • Closed Accounts Posts: 12 Aquafresh


    The following should work:
    cat data | gawk 'BEGIN{ORS=""} {if(NR % 3 == 1) print; else if(NR % 3 == 2) print " "$0; else print "\n"}'
    

    i.e. print the first line, a space, the second line, a new line and so on for all lines mod 3. You need the ORS="" because the default output record seperator is "\n" and you don't want newlines between the first and second record etc.


Advertisement