Combine output on same line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Combine output on same line
# 1  
Old 01-11-2008
Combine output on same line

I am trying to get some data from a file and print it on the same line.
I have a script that gets the date/time and calculates a DB query call time and sends to a file. I need to take this file and send it in a xcel like format with multiple data columns.

example output file (fndbq.out)

01/11/08 10:29:05
Elapsed: 00:00:00.27
01/11/08 10:29:37
Elapsed: 00:00:00.29
01/11/08 10:30:08
Elapsed: 00:00:00.25

I need it to look like this

01/11/08 10:29:05 | Elapsed: 00:00:00.27
01/11/08 10:29:37 | Elapsed: 00:00:00.29
01/11/08 10:30:08 | Elapsed: 00:00:00.25

I am having trouble this isn't working as expected.......

Code:
#!/bin/sh
clm1= grep / fndbq.out
clm2= grep Elapsed fndbq.out

printf $clm1 | $clm2

# 2  
Old 01-11-2008
One possibility with awk:

Code:
awk '!f{a=$0;f=1;next}{printf("%s | %s\n", a, $0); f=0}' file

Regards
# 3  
Old 01-11-2008
perfect, thanks so much.
# 4  
Old 01-14-2008
Another way using sed an awk:
Code:
>  sed -e '$!N' -e 's/\n/ \| /g'  file                       
01/11/08 10:29:05 | Elapsed: 00:00:00.27
01/11/08 10:29:37 | Elapsed: 00:00:00.29
01/11/08 10:30:08 | Elapsed: 00:00:00.25

Code:
> awk '( NR%2 != 0){printf("%s | ",$0);next}1 ' file
01/11/08 10:29:05 | Elapsed: 00:00:00.27
01/11/08 10:29:37 | Elapsed: 00:00:00.29
01/11/08 10:30:08 | Elapsed: 00:00:00.25


Last edited by Klashxx; 01-14-2008 at 07:38 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Get an output of lines in pattern 1st line then 10th line then 11th line then 20th line and so on.

Input file: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 (6 Replies)
Discussion started by: Sagar Singh
6 Replies

2. Shell Programming and Scripting

Combine incrimental line

hi guys, i am writing a bash script.. that produce output some thing like this: road 100 300 500 road 100 300 500 road 100 300 500 road 100 300 500 street 400 200 700 street 400 200 700 path 200 100 900 i would like to combine all the entries that having the same but incremental (not... (12 Replies)
Discussion started by: pedot
12 Replies

3. UNIX for Dummies Questions & Answers

Combine Both Output from the awk Script

Hi, Is there anyway to combine output from the awk scripting. file01.txt: AUE_CHMOD AUE_CHOWN AUE_CHROOT AUE_CONNECT AUE_ACCEPT AUE_FCHOWN AUE_FCHMOD AUE_SETREUID AUE_SETREGID AUE_FCHROOT AUE_PFEXEC AUE_SETUID AUE_NICE AUE_SETGID (9 Replies)
Discussion started by: alvinoo
9 Replies

4. Shell Programming and Scripting

awk to combine lines from line with pattern match to a line that ends in a pattern

I am trying to combine lines with these conditions: 1. First line starts with text of "libname VALUE db2 datasrc" where VALUE can be any text. 2. If condition1 is met then continue to combine lines through a line that ends with a semicolon. 3. Ignore case when matching patterns and remove any... (5 Replies)
Discussion started by: Wes Kem
5 Replies

5. Shell Programming and Scripting

Pipe or combine output of three awk commands

What is the correct syntax to pipe or run three awk commands? Basically, using the output of the first awk as input in the second. Then using the output of the second awk in the third. Thank you :). awk 'FNR==NR {E; next }$3 in E {print $3, $5}' panel_genes.txt RefSeqGene.txt > update.txt |... (3 Replies)
Discussion started by: cmccabe
3 Replies

6. Shell Programming and Scripting

Combine multiline to one line till a blank line

Hello, I have a file as :- ABC DEF GHI JKL <BlankLine> MNO PQR STU VWX <BlankLine> YZA I need it as below:- ABCDEFGHIJKL; MNOPQRSTUVWX; (3 Replies)
Discussion started by: jassi10781
3 Replies

7. Shell Programming and Scripting

How to combine 2 files and output the unique & difference?

Hi Guys, I have two input files and I want to combine them and get the unique values and differences and put them into one file. See below desired output file. Inputfile1: 1111111 2222222 3333333 7860068 7860069 7860071 7860072 Inputfile2: 4444444 (4 Replies)
Discussion started by: pinpe
4 Replies

8. Shell Programming and Scripting

Combine line before the pattern

Hi, I am not very familiar with sed and awk and i have a huge file to process which is impossible to do manually. I want to print out beginning from "Network" until end of line only (excluding the Version). AND. the decription to be all in one line. File: Version: 2.0 Network: xxx... (9 Replies)
Discussion started by: The One
9 Replies

9. UNIX for Dummies Questions & Answers

combine files line by line

Hi all, I once knew of a simple unix command to do this, but I can't remember it and I can't find it by searching. I have two files. ### FILE A #### A1 A2 A3 A4 A5 ### FILE B #### B1 B2 B3 B4 B5 (2 Replies)
Discussion started by: Digby
2 Replies

10. Shell Programming and Scripting

Combine Two Commands Output

How i can combine output of two commands in one file.......i tried this but it is not working although each command is working good seperately..... head -1 filename | tail -1 filename i think there is problem with command concatenator? (16 Replies)
Discussion started by: 33junaid
16 Replies
Login or Register to Ask a Question