awk / shell - Fix broken lines and data


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 1  
sed or awk or shell - Fix broken lines and data

Gurus,
I am struggling with a issue and thought I could use some of your expertise.

Need Help with this

I have a flat file that has millions of records

24|john|account ~ info |56|
25|kuo|account ~ journal |58|
27|kim|account ~ journal |59|
28|San|account ~
journal |60|
29|jay|account ~ journal |26|
29|Nan|account ~
journal |66|
30|Kee|account ~ journal |27|

Need the following
- Replace the ~ with space ' ' from the flat file
- Join the broken lines together.
All lines end with a pipe "|" delimiter

Required Output

24|john|account info |56|
25|kuo|account journal |58|
27|kim|account journal |59|
28|San|account journal |60|
29|jay|account journal |26|
29|Nan|account journal |66|
30|Kee|account journal |27|

Thanks,

Last edited by rimss; 06-01-2006 at 03:53 AM..
# 2  
Try...
Code:
awk '{sub(/ ~/,""); printf $0 ($0~/\|$/?ORS:"")}' file1 > file2

# 3  
Thanks a lot - Ygor

It worked fine.

Its almost mid night and i was fire fighting this .. Finally get to sleep now

Thanks a lot ... for the quick reply !!!
# 4  
Quote:
Originally Posted by Ygor
Code:
awk '{sub(/ ~/,""); printf $0 ($0~/\|$/?ORS:"")}' file1 > file2

Code:
awk '{sub(/~ */,x);printf $0(/\|$/?ORS:x)}'

Code:
awk '{sub(/~ */,x);sub(/\|$/, "|\n")}8' ORS="" file1 >file2

Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #710
Difficulty: Easy
Chrome DevTools. when you want to inspect the styles or attributes of a DOM node , right-click the element and select Inspect.
True or False?

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

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

3. Shell Programming and Scripting

Joining broken lines with awk or perl

Hi, I have a huge file with sql broken statements like: PP3697HB @@@@0 <<<<<<Record has been deleted as per PP3697HB>>>>>> FROM sys.xtab_ref rc,sys.xtab_sys f,sys.domp ur WHE RE rc.milf = ur.milf AND rc.molf = f.molf AND ur.dept = 'SWIT'AND ur .department = 'IND' AND share = '2' AND... (4 Replies)
Discussion started by: som.nitk
4 Replies

4. Shell Programming and Scripting

awk - sed :Help Getting next lines data .

Experts, Can you please help how to get the output that are written just below "bad" calls badcalls nullrecv 439486 54 0 badlen xdrcall dupchecks ... (6 Replies)
Discussion started by: rveri
6 Replies

5. UNIX and Linux Applications

fix broken avi index

I need some recommendations on programs to fix broken avi index. Please tell me what your experiences have been with the program. Which programs work and which ones don't work. (1 Reply)
Discussion started by: cokedude
1 Replies

6. Ubuntu

How to fix broken packages?

I had played with the boost development packages for a while ago and now Synaptic fails to remove or add new packages, giving the below error report: E: /var/cache/apt/archives/libboost-system_111111-natty_i386.deb: trying to overwrite '/usr/lib/libboost_system-mt.so', which is also in package... (1 Reply)
Discussion started by: xyzt
1 Replies

7. Shell Programming and Scripting

Merge broken lines

i have a file of this type: SEAT-RES¦$D0317.PBOUC32A.GURD3591 ¦00000100¦201203161000¦B¦32 ¦2WN¦EUS-¦MAN¦VAS¦4827¦TTL011 ¦ SEAT-RES¦$D0317.PBOUC32A.GURD3591 ¦00000101¦201203161000¦B¦25 ¦2WN¦EUS-¦MAN¦VAS¦4827¦TTL011 ¦ ... (22 Replies)
Discussion started by: ashwin_winwin
22 Replies

8. Shell Programming and Scripting

Joining broken lines

I have a plain test file with a delimeter ''. In this file some lines are broken into two. The first part of these broken line will have 6 columns and the second part will have 4. These broken lines will be consicutive. I want to join the two consicutive lines which are having 6 fields and 4... (8 Replies)
Discussion started by: ratheeshjulk
8 Replies

9. Shell Programming and Scripting

Extracting specific lines of data from a file and related lines of data based on a grep value range?

Hi, I have one file, say file 1, that has data like below where 19900107 is the date, 19900107 12 144 129 0.7380047 19900108 12 168 129 0.3149017 19900109 12 192 129 3.2766666E-02 ... (3 Replies)
Discussion started by: Wynner
3 Replies

10. Shell Programming and Scripting

how to awk a data from seperate lines

Hi guys, i have a problem which im hoping you will be able to help me with. I have follwing output :- ------------------------------------------------------------------------------- NSTEP = 407000 TIME(PS) = 43059.000 TEMP(K) = 288.46 PRESS = 0.0 Etot = -2077.4322 ... (2 Replies)
Discussion started by: Mish_99
2 Replies

Featured Tech Videos