How to combine text data into one line?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to combine text data into one line?
# 1  
Old 05-02-2008
How to combine text data into one line?

The following input needs to be manipulated as follows:

INPUT from file or results of command:
============start:
Medium identifier : a45c0213:47eb5485:0aec:0321
Medium label : SQL Disk_11516
Location : [Windows_System_Library: /backup_09/a45c0213547eb4d2750aec50315.fd]
Protected : None
Medium identifier : a45c0213:47f09a86:0bbb:00d5
Medium label : SQL Disk_11582
Location : [Windows_System_Library: /backup_02/a45c0213547f08c5250bbb500ce.fd]
Protected : None
Medium identifier : a45c0213:47ecac55:0aec:040a
Medium label : SQL Disk_11536
Location : [Windows_System_Library: /backup_02/a45c0213547ecac5550aec50408.fd]
Protected : None
Medium identifier : a45c0213:47f5e816:0b15:01bc
Medium label : SQL Disk_11609
Location : [Windows_System_Library: /backup_09/a45c0213547f5e81650b15501ba.fd]
Protected : 05/04/08 04:55:56
Medium identifier : a45c0213:47fb2681:1e72:0052
Medium label : SQL Disk_11649
Location : [Windows_System_Library: /backup_10/a45c0213547fb268151e725004f.fd]
Protected : 05/08/08 04:50:02
finish====================
Notes: the results are formatted so that the first ":" lines up.

The ========start and finsih======= are not part of the results

Need to process the input so that the results yield:
a45c0213:47fb2681:1e72:0052,SQL Disk_11649,/backup_10/a45c0213547fb268151e725004f.fd,None[orthe date shown next to Protected]

(all on 1 line)

Each record Starts with the Medium identifier line and ends with the Protected line.

Thank you.
# 2  
Old 05-02-2008
Something along these lines.

nawk -f rcky.awk myInputFile

rcky.awk:
Code:
/^Medium identifier/,/^Protected/ {
  printf("%s%c", substr($0, index($0, ":")+2), ($0 ~ /^Protected/) ? "\n" : ",")
}


Last edited by vgersh99; 05-02-2008 at 02:28 PM.. Reason: anchors
# 3  
Old 05-02-2008
Thank you. Works just fine!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Combine data out of 3 files into one new file

Hi, How can I combine the data of of three files into one new file? I try to give as much informations as possible. The three existing files are called file1 file2 and file3 the new file should named output_combined. The size of the files will be around 900 words/lines each .. but always... (5 Replies)
Discussion started by: MyMemberName
5 Replies

3. Shell Programming and Scripting

Combine data from two files base on uniq data

File 1 ID Name Po1 Po2 DD134 DD134_4A_1 NN-1 L_0_1 DD134 DD134_4B_1 NN-2 L_1_1 DD134 DD134_4C_1 NN-3 L_2_1 DD142 DD142_4A_1 NN-1 L_0_1 DD142 DD142_4B_1 NN-2 L_1_1 DD142 DD142_4C_1 NN-3 L_2_1 DD142 DD142_3A_1 NN-41 L_3_1 DD142 DD142_3A_1 NN-42 L_3_2 File 2 ( Combination of... (1 Reply)
Discussion started by: pareshkp
1 Replies

4. Shell Programming and Scripting

Combine/omit data from 2 files

i made a script on my own. this is for the inventory to all of my AWS servers, and i run it to all of my servers to get the hostname, please look at file2. Then i need some data in file3 as well,. i need to combine them #cat file1 192.10.1.41 server.age.com ###### 192.10.0.40 ssh cant... (10 Replies)
Discussion started by: kenshinhimura
10 Replies

5. Shell Programming and Scripting

How to combine the data of files?

I have a main file as follows aaa 3/2 = 1.5 aba 55+6 = 61 aca 67+8 = 75 hjk 3+3 = 67 ghd 66+30 = 96 ghj 99-3 = 96 ffg 67+3 = 70 I have 4 sub files named sub1, sub2, sub3, sub4 content of sub1 aaa 23+5 = 28 hjk 45+6 = 51 ghd 40-20 = 20 ... (2 Replies)
Discussion started by: jackevan
2 Replies

6. Shell Programming and Scripting

Combine multiple unique lines from event log text file into one line, use PERL or AWK?

I can't decide if I should use AWK or PERL after pouring over these forums for hours today I decided I'd post something and see if I couldn't get some advice. I've got a text file full of hundreds of events in this format: Record Number : 1 Records in Seq : ... (3 Replies)
Discussion started by: Mayday22
3 Replies

7. Shell Programming and Scripting

Formatting a text file to get data in exact line by line

I have my data something like this SERIAL FIRSTOCCURRENCE NETPROTOCOL 1947430693 07/01/2009 05:16:40 FR SERIAL FIRSTOCCURRENCE NETPROTOCOL 1947430746 07/01/2009 05:18:05 FR I want the output as follows.... (1 Reply)
Discussion started by: rdhanek
1 Replies

8. Shell Programming and Scripting

writing data in a text file at particular line

I need to write value of variable $version at a particular line in a text file. Line number is determined by another variable &line......I don't know how to do it in shell script ... (2 Replies)
Discussion started by: punitpa
2 Replies

9. Shell Programming and Scripting

Reading data from a specific line in a text file

Hello, I have a problem which is giving me headache for days, can some please help. Please see code and text fiel below. Please see text in red for the problem I am facing # Program gets an input x from user while read line ; do echo... (4 Replies)
Discussion started by: jermaine4ever
4 Replies

10. Shell Programming and Scripting

Reading data from a specific line in a text file

hello, I have got the following problem that I am hoping someone can help with please. 1. I have got the following text file (below) , the columns data are 'Test Day', 'Board', 'Betting Number'. TEXT FILE ============================================ 1 3 02-01-27-28-29-30 0 1... (1 Reply)
Discussion started by: jermaine4ever
1 Replies
Login or Register to Ask a Question