-2

How to make the below given multiple lines to a single line in Linux?

I am able to do with xargs but end of the every line has one space extra.

From the below given output you can see 'JAS _Data' 'Exclusiv e' has a space.

Thu Feb 19 10:42:50: Submitted from host <iitmlogin5-ib0>, CWD <$HOME/Bipin/JAS _Data/Big_Domain/128np_IC/Normal_queue>, Output File <file .stdout.159375>, Error File <file.stderr.159375>, Exclusiv e Execution, 128 Task(s), Requested Resources <span[ptile= 16]>; RUNLIMIT

How to remove the extra space of each line and make it a single line?

[root@iitmlogin3 ~]# `bjobs -l 159375 | sed -n '/Submitted/,/RUNLIMIT/p' | xargs`
Thu Feb 19 10:42:50: Submitted from host <iitmlogin5-ib0>, CWD <$HOME/Bipin/JAS _Data/Big_Domain/128np_IC/Normal_queue>, Output File <file .stdout.159375>, Error File <file.stderr.159375>, Exclusiv e Execution, 128 Task(s), Requested Resources <span[ptile= 16]>; RUNLIMIT
[root@iitmlogin3 ~]#
fedorqui
  • 275,237
  • 103
  • 548
  • 598
  • this isn't enough to go on. What command(s) are you running with `xargs`? What is the input side of the pipe to xargs? Consider constructing a small test case that will allow readers to copy/paste to their machine and see the problem. – shellter Feb 28 '15 at 04:20
  • 2
    Your sample data did not contain any lines, which makes it difficult to work out what's up. Because that text was not indented, the text in angle brackets was not visible in the question. There are a number of spaces in odd places. Please revise the sample data so it accurately represents what you see; then select it and use the **`{}`** button above the edit box to indent the text as 'code'. – Jonathan Leffler Feb 28 '15 at 04:21
  • how to delete 1 space end of each line ? – user3742796 Feb 28 '15 at 04:36
  • 1
    For your own safety and the safety of the systems you are administering, don't experiment with that sort of script while running as `root`. You can do so much mischief by accident. And please, I told you how to make sure that your code fragments are legible — please do it! I can't work out what you're trying to do. I'm hoping the back-quotes around `bjobs … xargs` are not really part of your command line. I've not seen `xargs` run with no command given, though I see that [POSIX](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/xargs.html) says "no command means use `echo`". – Jonathan Leffler Feb 28 '15 at 04:37
  • from the above given line, I want to extract the values No of tasks i.e '128' and '16' ptile. want to read this values in variable Task = 128 ptile = 16 Thu Feb 19 10:42:50: Submitted from host , CWD <$HOME/Bipin/JAS_Data/Big_Domain/128np_IC/Normal_queue>, Output File , Error File , Exclusive Execution, 128 Task(s), Requested Resources ; RUNLIMIT – user3742796 Feb 28 '15 at 06:24

1 Answers1

2

If all you want to do is read multiple lines on standard input and concatenate them to a single line then you can use a while loop with printf:

while read line; do printf "$line"; done

You can pipe the output of whatever other commands you have to that, e.g.:

bjobs -l 159375 | sed -n '/Submitted/,/RUNLIMIT/p' | while read line; do printf "$line"; done
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
ccarton
  • 3,556
  • 16
  • 17
  • and also please help extract values 'Task(s)' and ptile of from before given line and store into variable i.e task = 128 ptile = 16 Thu Feb 19 10:42:50: Submitted from host , CWD <$HOME/Bipin/JAS_Data/Big_Domain/128np_IC/Normal_queue>, Output File , Error File , Exclusive Execution, 128 Task(s), Requested Resources ; – user3742796 Feb 28 '15 at 17:57
  • 3
    @user3742796 You already asked that in http://stackoverflow.com/questions/28778794/extract-value-and-read-as-variable and you got an answer. If you have trouble getting it to work, then edit that question with the exact script you are using that is not working and get help there. – ccarton Feb 28 '15 at 18:20