Replace \n char in Data

Tags
advanced, char, dat, data, ed, input, line, put, replace, \n

 
Thread Tools Search this Thread
# 8  
Old 11-22-2018
This works for your input data:

Code:
awk -F'|' '$1 ~ /^[0-9]+$/ { if(T) print T; T=$0; next; }
{ T = T " " $0; }
END { if(T) print T; }' allnum.txt

...but cannot be 100% reliable as Don Cragun says. It relies on the first field being all numbers, and if the broken line ever manages to imitate that, it will be fooled. And if | ever appears in a record nothing good will happen.

Last edited by Corona688; 11-22-2018 at 11:44 AM..
# 9  
Old 11-25-2018
Thanks Rudi C,
In my file total fields are 17 and expected pipes are 16
Your command is working fine in case of extra pipes also i.e more than 16 pipes. Can you please help me with expalanation how its working in case of extra pipes in data.
Please find below input and output after applying your command.
I will be very Thankful to you !!!!


Input:
Below rows have extra pipes than expected:
1st row (19 pipes),2nd row (18 pipes, \n in data ),3rd row (19 pipes)

Below rows have no Extra pipes i.e 16 pipes as expected.
4th (row has \n in data ),5th row has no extra pipes i.e 16 pipes

Input:
Code:
3071454|Organizer|324888|Filing|Bailey | Stock | Harmon | Cottam P.C.||||||||||||
333333|DDD|97233|UUUUUU REP||AMAR||AJAY||P.O. Box 69 MMMMMMMMMM JJ 6666||
JJJ BBBB P.O. Box 4 MMMMMMMMMM JJ 44444
delmer Speidel P.O. Box 242 MMMMMMMMMM JJ 99456, See File For More.....|||||||
3182134|Organizer|339933|Filing|BAILEY | STOCK | HARMON | COTTAM P.C.||||Registered Agent|221 E 21st St, Cheyenne, Laramie County, WY  82001|||||||
888888|Director|97382|UUUUUU REP||ANTHONY|K|JOSHI||1144 JNM ROAD LLLLLLLLLLLLL JJ 82513, Laurie Ideker, Leon Sanderson
coralie Emmons P.O. Box 34 LLLLLLLLLLLLL JJ 82513
wanda Knowles P.O. Box 958 LLLLLLLLLLLLL JJ 82513, See File For More...|||||||
999999|President|97692|UUUUUU REP||See||File|||||||||


Output:

Code:
3071454|Organizer|324888|Filing|Bailey | Stock | Harmon | Cottam P.C.||||||||||||
333333|DDD|97233|UUUUUU REP||AMAR||AJAY||P.O. Box 69 MMMMMMMMMM JJ 6666|| JJJ BBBB P.O. Box 4 MMMMMMMMMM JJ 44444 delmer Speidel P.O. Box 242 MMMMMMMMMM JJ 99456, See File For More.....|||||||
3182134|Organizer|339933|Filing|BAILEY | STOCK | HARMON | COTTAM P.C.||||Registered Agent|221 E 21st St, Cheyenne, Laramie County, WY  82001|||||||
888888|Director|97382|UUUUUU REP||ANTHONY|K|JOSHI||1144 JNM ROAD LLLLLLLLLLLLL JJ 82513, Laurie Ideker, Leon Sanderson coralie Emmons P.O. Box 34 LLLLLLLLLLLLL JJ 82513 wanda Knowles P.O. Box 958 LLLLLLLLLLLLL JJ 82513, See File For More...|||||||
999999|President|97692|UUUUUU REP||See||File|||||||||


Last edited by Neo; 11-26-2018 at 12:19 AM..
# 10  
Old 11-25-2018
Quote:
Originally Posted by rajeshkumare
Thanks Rudi C,
In my file total fields are 17 and expected pipes are 16
Your command is working fine in case of extra pipes also i.e more than 16 pipes. Can you please help me with expalanation how its working in case of extra pipes in data.
...
Not sure I understand your question. Additional lines will be read and appended to $0 until there are 17 fields in $0. No distinction is made between pipe field separators and "extra pipes". Should your input have many "extra pipes" in early fields, that method may fail and still leave you with truncated lines.
Should that become a problem, see posts #5 and #7.

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Replace \n char true line Separator rajeshkumare UNIX for Advanced & Expert Users 1 11-22-2018 07:30 AM
Replace the unexpected newline char with space in a Fixed width file deepakwins UNIX for Dummies Questions & Answers 5 08-08-2014 06:26 PM
Match a char with duplicates in a line and replace one of them redse171 Shell Programming and Scripting 5 05-22-2014 02:48 PM
Replace Char in XML Base on Condition asavaliya Shell Programming and Scripting 4 03-20-2014 01:15 PM
To find char field and replace null rohit_shinez Shell Programming and Scripting 5 08-07-2013 02:21 PM
Replace char between chars - help needed go0ogl3 Shell Programming and Scripting 10 07-07-2012 10:57 AM
Find and replace all extended char. asavaliya Shell Programming and Scripting 4 04-10-2012 02:19 PM
I don't know how to replace input char with appropriate integer solaris_user Programming 6 10-09-2011 11:19 PM
UNIX BASH replace char with dash w/o SED needsomehelp UNIX for Dummies Questions & Answers 11 10-08-2011 09:47 PM
Replace char on text file phillipss Shell Programming and Scripting 2 12-11-2010 01:19 AM
In vi editor I want to replace next line char by space RahulJoshi Shell Programming and Scripting 5 09-17-2010 05:44 AM
Special Char in Data file Amit.Sagpariya Shell Programming and Scripting 1 01-14-2010 06:05 PM
SED: Place char at starting and replace selected line hkansal Shell Programming and Scripting 2 06-11-2009 03:42 AM
How to replace any char with newline char. mightysam Shell Programming and Scripting 5 09-18-2008 09:15 PM
How to check a column contain numeric or char data type ?? jambesh Shell Programming and Scripting 12 10-06-2006 11:37 AM