0

i have next output:

/url-param-for-domain1
domain1.com.
/url-param-for-domain2
domain2.com.

How to possible transform it to:

domain1.com/url-param-for-domain1
domain2.com/url-param-for-domain2

Many thanks

beliy
  • 445
  • 6
  • 13
  • Show us your efforts please, even if they are futile – Inian Aug 30 '17 at 09:32
  • I'm not sure this is a duplicate, the lines need merging in a slightly different way (line2/line1, line4/line3, etc., rather than line1/line2, line3/line4, etc.) – Tom Aug 30 '17 at 09:36
  • @Inian i dont know how do it – beliy Aug 30 '17 at 09:37
  • @tripleee , it doesn't duplicate – beliy Aug 30 '17 at 09:39
  • 1
    If you don't care about speed and traversing the input multiple times: `tac input.txt | paste - - -d "" | tac`. `tac` is like a reverse `cat` so will output the file line by line starting from the end and going backwards. `paste - -` will join every two lines. The `tac` at the end is to restore the original order. – Tom Aug 30 '17 at 09:39
  • @Tom, many thanks, i think tac can help, but `paste - - -d "" ` don't remove extra dot after domain. – beliy Aug 30 '17 at 09:47
  • @beliy you should be able to find some answers on stackoverflow about how to remove the dot if you search – Tom Aug 30 '17 at 09:50
  • @beliy: You can make an attempt from this answer - https://stackoverflow.com/a/9605559/5291015 – Inian Aug 30 '17 at 09:53
  • 2
    [I added a comment to the duplicate to explain a variant which should work for you](https://stackoverflow.com/questions/9605232/how-to-merge-every-two-lines-into-one-from-the-command-line#comment78871488_9605559). This remains a duplicate. – tripleee Aug 30 '17 at 09:54
  • @tripleee but after reorder i have syntax error. I'll try use as `awk 'NR%2{printf "%s ",next;$0;}1'` Please show where my mistakes – beliy Aug 30 '17 at 10:34
  • The `next` is not a field name, it's a command to Awk to process the next line. – tripleee Aug 30 '17 at 10:40
  • I [posted another comment](https://stackoverflow.com/questions/9605232/how-to-merge-every-two-lines-into-one-from-the-command-line#comment78874178_9605559) with a detailed solution. My bad. – tripleee Aug 30 '17 at 10:43
  • @tripleee, but `awk '!NR%2 { keep=$0; next } { printf "%s %s", $0, keep }' ngrep.txt` return: /url-param-for-domain1 domain1.com. /url-param-for-domain2 domain2.com. – beliy Aug 30 '17 at 10:53
  • Then switch the order of the print like I previously suggested. Thanks for following up -- I replaced the comment with a corrected one. – tripleee Aug 30 '17 at 11:27

0 Answers0