0

So far, I have this:

grep -B 36 'pattern1' Mapper.1.Configuration.MapRules | grep "pattern2" | cut -d'"' -f2

which give me a new-line delimited list of values that I need. I could put this into a file and then do a find and replace of all new-lines with commas.

But I'm guessing (nay, hoping!) there's a way to do this on the command line?

Ramy
  • 117
  • 1
  • 7

1 Answers1

1

A quick search shows the following answer from the Stack Exchange universe which should be applicable:

<command> | tr "\\n" ","

https://stackoverflow.com/questions/2764051/joining-multiple-lines-into-one-with-bash

USD Matt
  • 5,321
  • 14
  • 23
  • Thanks, for this. I was having trouble finding the right text to search on. This seems to work except that it's also taking the next command prompt as input...it seems. i.e. the last value has a comma after it but also has "root@ip-address:/current-dir" appended to it. This is a great lead though. i'll look into tr. – Ramy Mar 14 '14 at 15:00
  • It doesn't have the next prompt as input. The \n at the very end of the output is replaced by a comma, so the prompt printed by your terminal after the command completes doesn't go onto a new line. – USD Matt Mar 14 '14 at 15:02
  • ah. of course. I'll keep playing with it to get what i need. – Ramy Mar 14 '14 at 15:04
  • There's various extra bits on information on the stackoverflow question. You could also try appending `| sed 's/,$//'`. That removes the last comma and adds a newline for me although I am using FreeBSD so your output may vary slightly from mine. – USD Matt Mar 14 '14 at 15:07
  • thanks, for the tip. that sed command didn't work for me. I just removed the last character of the string like this: `${i%?}` where i stores the results of my pipeline (that ends with the tr command) – Ramy Mar 14 '14 at 15:37