0

The command I'm running is:

locate -b '\java' | xargs -ri  find {} -prune -type f -executable | xargs bash -c '$0 -version'

Below is the response

java version "1.6.0_41"
OpenJDK Runtime Environment (IcedTea6 1.13.13) (rhel-1.13.13.1.el6_8-x86_64)
OpenJDK 64-Bit Server VM (build 23.41-b41, mixed mode)

What I'm hoping to do is place this all on 1 line.

I've tried various sed and awk but is always comes back as 3 lines.

Rishabh Sagar
  • 1,744
  • 2
  • 17
  • 27
BostonMacOSX
  • 1,369
  • 2
  • 17
  • 38
  • 2
    What is output of `locate -b '\java'` command? – anubhava Feb 19 '20 at 18:30
  • 2
    Is the output of `java -version` going to stdout or stderr? Show at least one of the various sed and awk scripts you've tried so we can help you figure out what's wrong with it/them. – Ed Morton Feb 19 '20 at 18:44
  • @EdMorton locate -b '\java' | xargs -ri find {} -prune -type f -executable | xargs bash -c '$0 -version' | awk '{print $2}' this is not seeminig to do anything – BostonMacOSX Feb 19 '20 at 19:17
  • You didn't answer my question of `Is the output of java -version going to stdout or stderr? ` and `awk '{print $2}'` would print the 2nd space-separated field from every output line, that's nothing like what you're hoping to do (i.e. join multiple lines into 1) if I understand your question correctly. – Ed Morton Feb 19 '20 at 19:21
  • @EdMorton I was starrting simple just to see if I can see aany of the output at that stage of the pipe...it comes back wiith nothing so I'm not sure. I done know if -verion outputs to stdout or stderr.... – BostonMacOSX Feb 19 '20 at 19:28
  • @EdMorton locate -b '\java' | xargs -ri find {} -prune -type f -executable | xargs -i bash -c '{} -version 2>&1' | tr -d '\n' Seems to have remove the line endings. – BostonMacOSX Feb 19 '20 at 19:31
  • Yeah but that would **remove all line endings** which means consecutive lines would be joined together with no space between them so the last and first strings from each pair of lines would be smushed together, and it'd produce a string that's not a valid "text file" per the POSIX stanndard so YMMV with what any subsequent tool does with that. See [the awk command I posted](https://stackoverflow.com/a/60307783/1745001) for how to replace line endings with spaces rather than simply remove them and retain the terminating newline required of POSIX text lines/files. – Ed Morton Feb 19 '20 at 19:37
  • 1
    You are asking how to remove the line endings; that's how you do it. I see no indication in your question that you had explored this. – tripleee Feb 19 '20 at 19:41
  • @triplee makes a good point. You asked how to remove line endings whereas I provided a solution that will replace line endings except the final one with blanks and will retain the terminating line ending. If you [edit] your question to show the expected output for the 3 input lines you provided instead of just describing it (`Whaat i'm hoping to do iss place this all on 1 line.`) that would help remove any confusion/misunderstandings and clarify your requirements a lot. – Ed Morton Feb 19 '20 at 19:47

1 Answers1

1

Add:

| awk '{printf "%s%s", sep, $0; sep=OFS} END{print ""}'

to the end of your existing pipline. If that doesn't change the output then chances are it's going to stderr rather than stdout so then change the above to:

2>&1 | awk '{printf "%s%s", sep, $0; sep=OFS} END{print ""}'
Ed Morton
  • 188,023
  • 17
  • 78
  • 185