2 carriage return within a record


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting 2 carriage return within a record
# 8  
Old 08-18-2011
the actual input file,

Code:
VALUE_ID|HPB_DIV_DEPT|KPI_ID|KPI_DESC|YEAR|VERSION|KPI_VALUE|KPI_VALUE_NUM|KPI_PERFORM|VALUE_STATUS|INACTIVE_DATE|UPDATED_DATE|UPDATED_BY|REMARKS|CREATED_DATE|MODIFIED_DATE
HPB_001_V_01|HPB|HPB_001|Prevalence of
diabetes mellitus aged 18 - 69 years |1998|B|9%|9.00||A||20101201000000|HSID|||
HPB_001_V_02|HPB|HPB_001|Prevalence of diabetes mellitus aged 18 - 69 years |1998|R|9%|9.00||A||20101201000000|HSID|Testing
Remarks||
HPB_001_V_03|HPB|HPB_001|Prevalence of diabetes mellitus
aged 18 - 69 years |2004|R|8.2%|8.20||A||20101201000000|HSID|Test Test
Test||
HPB_001_V_04|HPB|HPB_001|Prevalence of diabetes mellitus aged 18 - 69 years |2010|R|11.3%|11.30|U|A||20101201000000|HSID|||

# 9  
Old 08-18-2011
Ok, and I assume that every line but the 1st should be appended so that all lines start with "HPB"?
# 10  
Old 08-18-2011
Code:
$> awk -F\| 'NR>1 && /^HPB/ {if(l){print l};l=$0; next} l {l=l $0; next}1' infile
VALUE_ID|HPB_DIV_DEPT|KPI_ID|KPI_DESC|YEAR|VERSION|KPI_VALUE|KPI_VALUE_NUM|KPI_PERFORM|VALUE_STATUS|INACTIVE_DATE|UPDATED_DATE|UPDATED_BY|REMARKS|CREATED_DATE|MODIFIED_DATE
HPB_001_V_01|HPB|HPB_001|Prevalence ofdiabetes mellitus aged 18 - 69 years |1998|B|9%|9.00||A||20101201000000|HSID|||
HPB_001_V_02|HPB|HPB_001|Prevalence of diabetes mellitus aged 18 - 69 years |1998|R|9%|9.00||A||20101201000000|HSID|TestingRemarks||
HPB_001_V_03|HPB|HPB_001|Prevalence of diabetes mellitusaged 18 - 69 years |2004|R|8.2%|8.20||A||20101201000000|HSID|Test TestTest||

If you want the ":::" as delimeter for the pasted parts, use:
Code:
$> awk -F\| 'NR>1 && /^HPB/ {if(l){print l};l=$0; next} l {l=l ":::" $0; next}1' infile
VALUE_ID|HPB_DIV_DEPT|KPI_ID|KPI_DESC|YEAR|VERSION|KPI_VALUE|KPI_VALUE_NUM|KPI_PERFORM|VALUE_STATUS|INACTIVE_DATE|UPDATED_DATE|UPDATED_BY|REMARKS|CREATED_DATE|MODIFIED_DATE
HPB_001_V_01|HPB|HPB_001|Prevalence of:::diabetes mellitus aged 18 - 69 years |1998|B|9%|9.00||A||20101201000000|HSID|||
HPB_001_V_02|HPB|HPB_001|Prevalence of diabetes mellitus aged 18 - 69 years |1998|R|9%|9.00||A||20101201000000|HSID|Testing:::Remarks||
HPB_001_V_03|HPB|HPB_001|Prevalence of diabetes mellitus:::aged 18 - 69 years |2004|R|8.2%|8.20||A||20101201000000|HSID|Test Test:::Test||

# 11  
Old 08-19-2011
Thanks zaxxon for your reply, sad to say that it is not working...
# 12  
Old 08-19-2011
Quote:
Originally Posted by agathaeleanor
Thanks zaxxon for your reply, sad to say that it is not working...
How is it not working? Post any error messagees and/or describe how the output deviates from your expectations. Also, you posted a sample input file in post #8 but not the corresponding desired output. You're making it very difficult to provide effective assistance.

Regards,
Alister
# 13  
Old 08-19-2011
It is not working as if the output swapped between the first chunk of the carriage return with second chunk of the carriage return.

input sample:
Code:
a|b|c|d
e|e|f|g|h

Output:
Code:
e|e|f|g|h
a|b|c|d

I have compensated the actual input file thus zaxxon provided the solution as

Code:
awk -F\| 'NR>1 && /^HPB/ {if(l){print l};l=$0; next} l {l=l $0; next}1' infile

or

Code:
awk -F\| 'NR>1 && /^HPB/ {if(l){print l};l=$0; next} l {l=l ":::" $0; next}1' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Remove carriage return

I need to remove the carriage return comes inbetween the record. Need to have CR only at the end. I used the below command. tr -d '\n' < filewithcarriagereturns > filewithoutcarriagereturns But its removing all the CR and giving one line output. Input File: 12345 abcdegh... (11 Replies)
Discussion started by: srvn_saru
11 Replies

2. Shell Programming and Scripting

Substitute \n with carriage return

Hello all, I've a flat file in the following format: AB\001\CDED\001\ABC\001\nEG\001\HIJF\001\EFG\001\nHI\003\HIUL\003\HIJ\003 And I want to substitute \n with the carriage return. Any help is appreciated! Regards, - Seth (8 Replies)
Discussion started by: sethmj
8 Replies

3. Shell Programming and Scripting

Carriage return ksh

Hello, How do i usecarriage return in ksh. I want to do an echo "bla bla" and another echo "bla bla" will appear and replace the first echo on screen. I tried: until ; do echo "bla bla \r" done please advice. Thanks. (3 Replies)
Discussion started by: LiorAmitai
3 Replies

4. Shell Programming and Scripting

Search_Replace with a Carriage Return

Hey folks, I've been working on this for some time. Seems simple, but I'm stumped. I need the following data format: New_York:Commercial Geology Geophysics Petrophysics Production_Engineering Reservoir_Engineering Pasadena:Commercial ... (5 Replies)
Discussion started by: leepet01
5 Replies

5. Shell Programming and Scripting

Remove carriage return in a record

Hi all gurus, I need help in removing carriage return existed within a record delimited by pipe <|>. Sample: A_01|Test1|Testing1|Remarks1 A_02|Test2|Test ing2|Remarks2 A_03|Test3|Testing3| Remarks3 Desire output: A_01|Test1|Testing1|Remarks1 A_02|Test2|Testing2|Remarks2... (10 Replies)
Discussion started by: agathaeleanor
10 Replies

6. Shell Programming and Scripting

Lost carriage return when assign

Hello . Now i have a different problem, lost "carriage return" when assigning a variable. The assignation is done in a peculair way but its ok. The variable "v_tmp" have spaces and carriage return. Its created with v_tmp=`echo $i | awk '.........'` And the assignation where i lost all the... (6 Replies)
Discussion started by: trutoman
6 Replies

7. UNIX for Dummies Questions & Answers

carriage return and linefeed

hi can anyone please tell me the difference between carriage return, linefeed and newline ? (2 Replies)
Discussion started by: streetfi8er
2 Replies

8. Shell Programming and Scripting

Dont want carriage return

I have observed with print & echo, they produce carriage return <CR> or newline, after they display string next to them. Is there anyway to avoide these <CR> after the intended string is displayed? (3 Replies)
Discussion started by: videsh77
3 Replies

9. Shell Programming and Scripting

Removing Carriage return to create one record

I have a file with multiple records in it and want to create a single record by removing all the carriage returns, is there a sed command or another command that will easily allow this to happen. current layout 813209A 813273C 812272B expected result 813209A813273C812272B previously I... (3 Replies)
Discussion started by: r1500
3 Replies

10. Shell Programming and Scripting

Capture carriage return.

I try to test the carriage return in a variable. $ LENGTH=`expr $VARIABLE : ".*"` will return the length of the variable. But this doesn't work if $VARIABLE has zero length. Any help will be well appreciated. Thanks in advance. Giovanni (4 Replies)
Discussion started by: gio123bg
4 Replies
Login or Register to Ask a Question