Text formatting - joining lines


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Text formatting - joining lines
# 1  
Old 01-22-2013
Text formatting - joining lines

I have large file with data as below, in unix using sed or some cammand how to get output as below.

cat 1.txt

Code:
Normal data
1|AA|NN
4|BB|NNN
C|DDD|N
//Additional details
9C|12C|8N
Specific Details
12N|JIN|KK\NY1\
345\ABC1\KKK
90|ENO0|NDO
17|NO921|NCOKL

output shoud be as below

Code:
1|AA|NN
4|BB|NNN
C|DDD|N
9C|12C|8N
12N|JIN|KK\NY1\345\ABC1\KKK
90|ENO0|NDO
17|NO921|NCOKL

Kindly suggest if some one knows it..

Last edited by radoulov; 01-22-2013 at 06:15 PM..
# 2  
Old 01-22-2013
Code:
awk '!/[Dd]etails/&&!/Normal/' 1.txt | sed '/[^a-zA-Z0-9]$/{h;N;s/\n//;}'

# 3  
Old 01-22-2013
You could use awk:

Code:
awk '
/Normal data/||/Additional details/||/Specific Details/ {next}
join { $0=join$0; join=x}
/\\$/{ join=$0; next}
1' 1.txt

# 4  
Old 01-22-2013
Thanks for the inputs, could you please suggest me in another way to delete the lines those are not having |, instead of mentioning like Normal data, Additional details..etc..since file is huge..need generic approach
# 5  
Old 01-22-2013
Will this work for you?
Code:
awk '/\|/||/\\/' 1.txt | sed '/[^a-zA-Z0-9]$/{h;N;s/\n//;}'

# 6  
Old 01-22-2013
Code:
grep '\|' $file

Never mind, I missed the record with the continued line, awk is the way to go.

Last edited by Skrynesaver; 01-22-2013 at 05:49 PM.. Reason: Missed the point of the query
# 7  
Old 01-22-2013
Is it possible to achieve using sed, with out awk
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Joining broken lines and removing empty lines

Hi - I have req to join broken lines and remove empty lines but should NOT be in one line. It has to be as is line by line. The challenge here is there is no end of line/start of line char. thanks in advance Source:- 2003-04-34024|04-10-2003|Claims|Claim|01-13-2003|Air Bag:Driver;... (7 Replies)
Discussion started by: Jackceasar123
7 Replies

2. UNIX for Dummies Questions & Answers

Removing PATTERN from txt without removing lines and general text formatting

Hi Everybody! First post! Totally noobie. I'm using the terminal to read a poorly formatted book. The text file contains, in the middle of paragraphs, hyphenation to split words that are supposed to be on multiple pages. It looks ve -- ry much like this. I was hoping to use grep -v " -- "... (5 Replies)
Discussion started by: AxeHandle
5 Replies

3. Shell Programming and Scripting

Joining lines in different way

Hi all, I'm excited to the part of unix.com forum, and noob to it. I have an query, where I have an file and it contains data like this use thread when posting do no I was expecting the result as use thread thread when when posting posting do do no use thread when thread when... (6 Replies)
Discussion started by: Jose Nirmal
6 Replies

4. Shell Programming and Scripting

Joining lines in a text file using AWK or SED

Hi All I'm struggling a bit here :( I need a way of joining lines contained in a text file. I've seen numerous SED and AWK examples and none of them seem to be working for me. The text file has 4 lines: DELL1427 DOC 30189342 79 Now bear with me on this one as I'm actually... (4 Replies)
Discussion started by: huskie69
4 Replies

5. UNIX for Dummies Questions & Answers

JOINING MULTIPLE LINES IN A TEXT FILE USING GAWK

sir... am having a data file of customer master., containing some important fields as a set one line after another., what i want is to have one set of these fields(rows) one after another in line.........then the second set... and so on... till the last set completed. I WANT THE DATA... (0 Replies)
Discussion started by: KANNI786
0 Replies

6. UNIX for Dummies Questions & Answers

Joining lines of a text file using GAWK

sir... am having a data file of customer master., containing some important fields as a set one line after another., what i want is to have one set of these fields(rows) one after another in line.........then the second set... and so on... till the last set completed. ... (0 Replies)
Discussion started by: KANNI786
0 Replies

7. Shell Programming and Scripting

pattern matching lines using the date, and then joining the lines

Hi Guys, Was trying to attempt the below using awk and sed, have no luck so far, so any help would be appreciated. Current Text File: The first line has got an "\n", and the second line has got spaces/tabs then the word and "\n" TIME SERVER/CLIENT TEXT... (6 Replies)
Discussion started by: eo29
6 Replies

8. Shell Programming and Scripting

Need help joining lines

Hi All, I need the command to join 2 lines into one. I found lots of threads but none give me the sollution. Probably because unix scripting is one of my best features ;) I got a logfile where line 2 needs to be joined with line 1, lines 4 needs to be joined with line 3 etc If you need... (16 Replies)
Discussion started by: rene21976
16 Replies

9. Shell Programming and Scripting

joining two lines

Hi , I want to join two lines in a file, where the second line contain query string. if it doesn't contain that string i don't want to join e.g. Input file is as following: name fame game none none none name fame game cat eat mice I need output file as name fame game none none... (2 Replies)
Discussion started by: ashrafonics
2 Replies

10. Shell Programming and Scripting

joining 2 lines into single one

i have a script that joins 2 lines of a file into one line and again next 2 line into one line. if number of line is 4 then after joining it should be 2 lines in a file my file a1.txt has some of the below lines 1-GH32X, CC, AMR, Number of Intervals Not Inserted: 1 / 95 1-150KP1, CC,... (3 Replies)
Discussion started by: ali560045
3 Replies
Login or Register to Ask a Question