Multi lines to single line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Multi lines to single line
# 1  
Old 12-19-2011
Multi lines to single line

HI,
My input file contains the data as like below:
Code:
A1234119993
B6271113
Bghjkjk
A1234119992
B6271113hi
Bghjkjkmkl

the output i require is :
Code:
A1234119993 B6271113 Bghjkjk
A1234119992 B6271113hi Bghjkjkmkl

Please help me in this.

Thanks
# 2  
Old 12-19-2011
insert a line break whenever "A" is the first character in the line:
Code:
awk ' /^A/ && ok {print ""}
       /^A/ {ok=1}
       {printf("%s ",$0) } ' inputfile

This User Gave Thanks to jim mcnamara For This Post:
# 3  
Old 12-19-2011
Quote:
Originally Posted by jim mcnamara
insert a line break whenever "A" is the first character in the line:
Code:
awk ' /^A/ && ok {print ""}
       /^A/ {ok=1}
       {printf("%s ",$0) } ' inputfile

Awesome!!can you please explain this code?

Thanks
# 4  
Old 12-19-2011
Hi Pandeesh

You can also try the following

code:

Code:
paste -s -d" " < filename


Last edited by zxmaus; 12-19-2011 at 12:16 PM..
# 5  
Old 12-19-2011
Quote:
Originally Posted by sdebasis
Hi Pandeesh

You can also try this following

code:

paste -s -d" " < filename
I dont think this will work.you are not checking any condition here.

---------- Post updated at 11:07 PM ---------- Previous update was at 09:38 PM ----------

there is a small change:

Code:
A1234119993 
B6271113 
Bghjkjk 
A1234119992 
B6271113hi 
Bghjkjkmkl

the output i require is :

Code:
  A1234119993 B6271113 
  A1234119993 Bghjkjk 
  A1234119992 B6271113hi 
  A1234119992 Bghjkjkmkl

How we can achieve this?

Thanks
# 6  
Old 12-19-2011
Code:
awk '
/^A/ { begin=$0  }   # line start A
/^B/ { print begin $0  }     # line start B
' inputfile

This User Gave Thanks to kshji For This Post:
# 7  
Old 12-20-2011
I'm sorry Pandeesh

For your previous requirement the code will be like:-

Code:
paste -s -d"  \n" < filename

Note:There should be two spaces and one new line as delemeter , I have only checked it in Redhat Enterprise4 (LINUX).

Last edited by Franklin52; 12-20-2011 at 05:36 AM.. Reason: Correcting code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Merge multi-lines into one single line using shell script or Linux command

Hi, Can anyone help me for merge the following multi-line log which beginning with a " and line ending with ": into one line. *****Original Log***** 087;2008-12-06;084403;"mc;;SYHLR6AP1D\LNZW;AD-703;1;12475;SYHLR6AP1B;1.1.1.1;0000000062;HGPDI:MSISDN=12345678,APNID=1,EQOSID=365;... (3 Replies)
Discussion started by: rajeshlinux2010
3 Replies

2. Shell Programming and Scripting

Multi line log files to single line format

I want to read the log file which was generate from other command . And the output was having multi line in log files for job name and server name. But i need to make all the logs on one line Source file 07/15/2018 17:02:00 TRANSLOG_1700 Server0005_SQL ... (2 Replies)
Discussion started by: ranjancom2000
2 Replies

3. Shell Programming and Scripting

Help with reformat single-line multi-fasta into multi-line multi-fasta

Input File: >Seq1 ASDADAFASFASFADGSDGFSDFSDFSDFSDFSDFSDFSDFSDFSDFSDFSD >Seq2 SDASDAQEQWEQeqAdfaasd >Seq3 ASDSALGHIUDFJANCAGPATHLACJHPAUTYNJKG ...... Desired Output File >Seq1 ASDADAFASF ASFADGSDGF SDFSDFSDFS DFSDFSDFSD FSDFSDFSDF SD >Seq2 (4 Replies)
Discussion started by: patrick87
4 Replies

4. Shell Programming and Scripting

joining multi-line file into single lines

Hi, I have a file like mentioned below..For each specific id starting with > I want to join the sequence in multiple lines to a single line..Is there a simple way in awk or sed to do this >ENST00000558922 cdna:KNOWN TCCAGGATCCAGCCTCCCGATCACCGCGCTAGTCCTCGCCCTGCCTGGGCTTCCCCAGAG... (2 Replies)
Discussion started by: Diya123
2 Replies

5. Shell Programming and Scripting

Joining multi-line output to a single line in a group

Hi, My Oracle query is returing below o/p ---------------------------------------------------------- Ins trnas value a lkp1 x a lkp1 y b lkp1 a b lkp2 x b lkp2 y ... (7 Replies)
Discussion started by: gvk25
7 Replies

6. Shell Programming and Scripting

Multi line document to single lines based on occurance of string

Hi Guys, I am new to awk and sed, i am working multiline document, i want to make make that document into SINGLE lines based on occurace of string "dwh". here's the sample of my problem.. dwh123 2563 4562 4236 1236 78956 12394 4552 dwh192 2656 46536 231326 65652 6565 23262 16625623... (5 Replies)
Discussion started by: victor369
5 Replies

7. Shell Programming and Scripting

How to use Perl to join multi-line into single line

Hello, Did anyone know how to write a perl script to merge the multi-line into a single line where each line with start at timestamp Input--> timestamp=2009-11-10-04.55.20.829347; a; b; c; timestamp=2009-11-10-04.55.20.829347; aa; bb; cc; (5 Replies)
Discussion started by: happyday
5 Replies

8. Shell Programming and Scripting

Help on Merge multi-lines into one single line

Hello, Can anyone let me know how to use Perl script to Merge following multi-lines into one single line... ***** Multi-line***** FILE_Write root OK Tue Jul 01 00:00:00 2008 cl_get_path file descriptor = 1 FILE_Write root OK ... (5 Replies)
Discussion started by: happyday
5 Replies

9. Shell Programming and Scripting

How to use Perl to merge multi-line into single line

Hi, Can anyone know how to use perl to merge the following multi-line information which beginning with "BAM" into one line. For each line need to delete the return and add a space. Please see the red color line. ******Org. Multi-line) BAM admin 101.203.57.22 ... (3 Replies)
Discussion started by: happyday
3 Replies

10. Shell Programming and Scripting

Merge multi-lines into one single line

Hi, Can anyone help me for merge the following multi-line log which beginning with a number and time: into one line. For each line need to delete the return and add a space. Please see the red color line. *****Original Log*****... (4 Replies)
Discussion started by: happyday
4 Replies
Login or Register to Ask a Question