Merge multiline into Singleline


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Merge multiline into Singleline
# 1  
Old 06-11-2009
Merge multiline into Singleline

Hi,

I'm newbie in this forum and I already searched regarding Merge multiline into singleline but I always found different result which is I don't want it like i want.

Here is the data that i have it:
*** ALARM 711 A1/BTS "MAD08B1 08ACPA0"U 090604 1040
RADIO X-CEIVER ADMINISTRATION
BTS EXTERNAL FAULT

MO RSITE CLASS
RXOCF-59 MD2026 1

EXTERNAL ALARM
TEMPERATURA ALTA
AIRE CONDICIONA
*** ALARM 710 A1/BTS "MAD08B1 08ACPA0"U 090604 1040
RADIO X-CEIVER ADMINISTRATION
BTS EXTERNAL FAULT

MO RSITE CLASS
RXOCF-97 MD2059 1

EXTERNAL ALARM
FUEGO
TEMPERATURA BAJA

And the output I would likes belows:
*** ALARM 711 A1/BTS "MAD08B1 08ACPA0"U 090604 1040 RADIO X-CEIVER ADMINISTRATION BTS EXTERNAL FAULT MO RSITE CLASS RXOCF-59 MD2026 1 EXTERNAL ALARM TEMPERATURA ALTA AIRE CONDICIONA
*** ALARM 710 A1/BTS "MAD08B1 08ACPA0"U 090604 1040 RADIO X-CEIVER ADMINISTRATION BTS EXTERNAL FAULT MO RSITE CLASS RXOCF-97 MD2059 1 EXTERNAL ALARM FUEGO TEMPERATURA ALTA


Is there any csh or Perl scripts to make it?

Thank you for your help.
Inteliduy
# 2  
Old 06-11-2009
This assumes your block of text always starts with * * *
Code:
awk ' {if(length(old)>0 && index("* * *", $0) > 0) 
            {print old; old=$0; next}
        old=old $0 
        } 
        END{ print old} ' logfile > newfile

# 3  
Old 06-11-2009
if you have Python
Code:
#!/usr/bin/env python
data=[i for i in open("file").read().split("***") if i != ""]
for item in data:
    print "***" + item.replace("\n","").strip()

output
Code:
# ./test.py
***ALARM 711 A1/BTS "MAD08B1 08ACPA0"U 090604 1040RADIO X-CEIVER ADMINISTRATIONBTS EXTERNAL FAULTMO RSITE CLASSRXOCF-59 MD2026 1EXTERNAL ALARMTEMPERATURA ALTAAIRE CONDICIONA
***ALARM 710 A1/BTS "MAD08B1 08ACPA0"U 090604 1040RADIO X-CEIVER ADMINISTRATIONBTS EXTERNAL FAULTMO RSITE CLASSRXOCF-97 MD2059 1EXTERNAL ALARMFUEGOTEMPERATURA BAJA

# 4  
Old 06-12-2009
Code:
while(<DATA>){
	chomp;
	if (/\*{3}/ && $.!=1){
		print "\n";
	}
	print $_," ";
}
__DATA__
*** ALARM 711 A1/BTS "MAD08B1 08ACPA0"U 090604 1040
RADIO X-CEIVER ADMINISTRATION
BTS EXTERNAL FAULT

MO RSITE CLASS
RXOCF-59 MD2026 1

EXTERNAL ALARM
TEMPERATURA ALTA
AIRE CONDICIONA 
*** ALARM 710 A1/BTS "MAD08B1 08ACPA0"U 090604 1040
RADIO X-CEIVER ADMINISTRATION
BTS EXTERNAL FAULT

MO RSITE CLASS
RXOCF-97 MD2059 1

EXTERNAL ALARM
FUEGO
TEMPERATURA BAJA

# 5  
Old 06-12-2009
Code:
 
cat inputfile.txt | tr "\n" " " | awk '{ print $0"\n" }' | sed 's/ \*\*\*/\
\*\*\*/g'

# 6  
Old 06-15-2009
All,

Thank you for your help and I will try it. I will let you know.

Thanks a lot,
Inteliduy
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed multiline problem

I'm trying to replicate the sed output on p.108 of Sed&Awk,by Doughery & Robbins, 2nd edition. I'm on a Windows 10 Surface Pro, running Cygwin for 64-bit versions of Windows. Input text saved in text file called data_p108.txt: Consult Section 3.1 in the Owner and Operator Guide for a... (9 Replies)
Discussion started by: prooney
9 Replies

2. Shell Programming and Scripting

Script solution as singleline ?

Hello My script has following line and output find path -type d | awk -F "/" 'NF == 4{print $3}' path/custype=Type1/logdate=20160414 path/custype=Type11122/logdate=20160414 But I need following output that I need custtype information between "" like... (4 Replies)
Discussion started by: msuluhan
4 Replies

3. Shell Programming and Scripting

Multiline sed

Hi guys, I am fairly comfortable with using the sed command if the string to be replaced is all on a single line. I was wondering is it possible to use sed command in a multiline way ? Say for example I have the below string on 2 different lines: { "key": "brandNameA", ... (3 Replies)
Discussion started by: Junaid Subhani
3 Replies

4. Shell Programming and Scripting

Convert Singleline to Multilines

Hi All, Could you please help to get the below output: Input: J1,ELLA_1,ISDR,JJK,TRS J2,ROSTER,JACK J3,HUP ... ... ... Output: J1,ELLA_1 J1,ISDR J1,JJK J1,TRS (3 Replies)
Discussion started by: unme
3 Replies

5. Shell Programming and Scripting

Need to get multiline input

As per my requirement, I need to get a multiline input. It can be stored in a file, that's not a problem. User will be prompted to enter steps. he should able to enter the steps in multiple lines by pressing enter. All I know in read command that reads the input till we press enter. Can someone... (5 Replies)
Discussion started by: annamalaikasi
5 Replies

6. Shell Programming and Scripting

MultiLine Patterns

Experts, I am novice unix user. At my work, most of our DBA's work on creating DDL's to create new tables in production. At every week we need to validate the scripts (do peer review) and it takes a while and also it is not effective when we have like 150 tables created in the scripts. I am... (3 Replies)
Discussion started by: ysvsr1
3 Replies

7. UNIX for Dummies Questions & Answers

Need Multiline sed help!!

Hey everyone, I'm new to sed and I need to create a script for inserting one line of code at the beginning of every method in a Xcode project (over 6,000 methods). Each method Structure is (+ or -) (Various declarations-- could span multiple lines) ({) I've tried for days, any guidance would be... (2 Replies)
Discussion started by: jimmyz
2 Replies

8. Shell Programming and Scripting

How to merge multiline into line begining with specific word

Hi, The file format is like the following. timestamp=2008-02-28-23.50.29.550675;category=CONTEXT;audit event=CONNECT; event correlator=2; database=CURDOMS;userid=inst3;authid=INST3; origin node=0;coordinator node=0; application id=AC122081.FA97.054468155029;application... (2 Replies)
Discussion started by: missyou
2 Replies

9. UNIX for Dummies Questions & Answers

Multiline Grep

How does one do a search for a multiline regular experssion and output the results to a file. I know this won't work since grep only searches single lines: egrep '<a>.*?</a>' source.xml > output.xml Here are some sample patterns I'd like to match and output to a single file: ... (4 Replies)
Discussion started by: tolmark
4 Replies
Login or Register to Ask a Question