How to remove line breaker


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to remove line breaker
# 1  
Old 05-05-2011
How to remove line breaker

Hi, unix Gurus,
I have a requriement as following,
source:
Code:
123, abc , bbccdd
     cde
     efg
124, acd, abcdee

expected result

Code:
123, abc cde efg, bbccdd
124, acd, abcdee

basically, I need remove column 2 link breaker, because right now, in source the column 2 contains 3 line in a row.
SmilieSmilie

Thanks in advance

Last edited by ken002; 05-06-2011 at 12:28 AM.. Reason: lineup records
ken002
# 2  
Old 05-05-2011
Try...
Code:
awk 'BEGIN{FS=OFS=","}function pr(){for(i=1;i<=n;i++)printf a[i] (i<n?OFS:ORS)}NF==3{if(a[1])pr();n=split($0,a);next}{a[2]=a[2] $0}END{pr()}' file1 > file2

This User Gave Thanks to Ygor For This Post:
# 3  
Old 05-05-2011
Code:
echo '123, abc , bbccdd
        cde
        efg
124, acd, abcdee' |awk '/ ,/{l=split($0,a,","); for(i=1;i<=l;i++) if(a[i]~/ $/) {x=i}}NF==1{a[x]=a[x]" "$1}! / ,/&&NF>1{for(i=1;i<l;i++) printf a[i] ","FS;print a[l];print $0;delete a}'
123,  abc  cde efg,  bbccdd
124, acd, abcdee

This User Gave Thanks to yinyuemi For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove new line starting with a numeric value and append it to the previous line

Hi, i have a file with multiple entries. After some tests with sed i managed to get the file output as follows: lsn=X-LINK-IN0,apc=661:0,state=avail,avail/links=1/1, 00,2110597,2094790,0,81,529,75649011,56435363, lsn=TM1ITP1-AM1ITP1-LS,apc=500:0,state=avail,avail/links=1/1,... (5 Replies)
Discussion started by: nms
5 Replies

2. Shell Programming and Scripting

Ksh: Read line parse characters into variable and remove the line if the date is older than 50 days

I have a test file with the following format, It contains the username_date when the user was locked from the database. $ cat lockedusers.txt TEST1_21062016 TEST2_02122015 TEST3_01032016 TEST4_01042016 I'm writing a ksh script and faced with this difficult scenario for my... (11 Replies)
Discussion started by: humble_learner
11 Replies

3. UNIX for Dummies Questions & Answers

How to remove fields space and append next line to previous line.?

awk 'BEGIN{FS = "Ç"} NR == 1 {p = $0; next} NF > 1 {print p; p = $0} NF <= 1 {p = (p " " $0)} END {print p}' input.txt > output.txt This is what the input data file looks like with broken lines Code: 29863 Ç890000000 Ç543209911 ÇCHNGOHG Ç000000001 Ç055 ... (4 Replies)
Discussion started by: cumeh1624
4 Replies

4. Shell Programming and Scripting

Want to remove a line feed depending on number of tabs in a line

Hi! I have been struggling with a large file that has stray end of line characters. I am working on a Mac (Lion). I mention this only because I have been mucking around with fixing my problem using sed, and I have learned far more than I wanted to know about Unix and Mac eol characters. I... (1 Reply)
Discussion started by: user999991
1 Replies

5. UNIX for Dummies Questions & Answers

Remove multi line and single line comments

Hi, I am trying to remove multi line and single line comments like examples below I have tried this pattern. it works fine for single line comments and multi line comments in a single line only. but this fails when the comments are extended in multiple lines as shown in the comment 2 of... (3 Replies)
Discussion started by: ahmedwaseem2000
3 Replies

6. AIX

GPFS quroum with tie-breaker disks

I read from gpfs implementation guide about node quorum with tie-breaker disks: In my testing environment, I have 4 AIX as quorum nodes, each node connected to 3 GPFS disks. All the 3 disks are configured to be tie-breaker disks. Then, I disconnect the network of 2 nodes, and then all gpfs file... (0 Replies)
Discussion started by: skeyeung
0 Replies

7. UNIX for Dummies Questions & Answers

Sed to remove only first line erroneously removes last line too

Hello everyone, This is my first posting. I have read the rules of this forum. I have searched many various threads and haven't found one that applies to my situation or suggestions to fix the issue. I do appreciate the help. I am trying to execute a basic UNIX script in a Solaris... (4 Replies)
Discussion started by: dqrgk0
4 Replies

8. Shell Programming and Scripting

Remove line based on string and put new line with parameter

Hi Folks, I am new to ksh, i have informatica parameter file that i need to update everyday with shell script. i need your help updating this file with new parameters. sample data $$TABLE1_DATE=04-27-2011 $$TABLE2_DATE=04-23-2011 $$TABLE3_DATE=03-19-2011 .......Highligned... (4 Replies)
Discussion started by: victor369
4 Replies

9. Shell Programming and Scripting

sed remove last 10 characters of a line start from 3rd line

hello experts, I need a sed command that remove last 10 characters of a line start from 3rd line. any suggestions? Thanks you (7 Replies)
Discussion started by: minifish
7 Replies
Login or Register to Ask a Question