Help with removing embedded linefeeds


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with removing embedded linefeeds
# 1  
Old 07-15-2011
Help with removing embedded linefeeds

Greetings all,

i have csv file with pipe separated columns

SSN|NAME|ADDRESS|FILLER
123|abc|myaddress|xxx
234|BBB|my
add
ress
broken up|yyy

In the example above, the second record is broken into multiple lines. I need to keep going until I find a "|" since this issue is with the non-last column and therefore there definitely will be a pipe at the end of that column text.

is there any way i can remove \n (newline) from the address column?

Thanks for the help.
# 2  
Old 07-15-2011
Try:
Code:
awk -F"|" 'NF<4{ORS=" ";p=1}NF==1{p=1}NF==4&&p{printf "\n";ORS="\n";p=0}1' file

# 3  
Old 07-15-2011
meh. bartus11 beat me to it and his is more elegant. Smilie

Last edited by neutronscott; 07-15-2011 at 01:58 PM.. Reason: delete
# 4  
Old 07-15-2011
Thanks guys. I guess as long as I know the number of columns in the record, I can tweak this awk code to strip out linefeeds embedded in columns.
# 5  
Old 07-25-2011
If my number of columns is in a shell variable num_cols, how do I reference that from this awk code?
# 6  
Old 07-25-2011
I guess this should work:
Code:
awk -F"|" -vn=$num_cols 'NF<n{ORS=" ";p=1}NF==n{p=1}NF==4&&p{printf "\n";ORS="\n";p=0}1' file

# 7  
Old 07-25-2011
I get

nawk: can't open file NF<n{ORS=" ";p=1}NF==1{p=1}NF==n&&p{printf "\n";ORS="\n";p=0}1

---------- Post updated at 03:23 PM ---------- Previous update was at 03:22 PM ----------

works on command line though
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

WARNING! 16126 bare linefeeds received in ASCII mode

I am doing FTP from a server and getting below ERROR:WARNING! 16126 bare linefeeds received in ASCII mode File may not have transferred correctly. I looked into web and found that I may need to change the mode to binary, but when I do so the records are not in readable format...So need the file... (10 Replies)
Discussion started by: joshilalit2004
10 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

Add missing linefeeds between formfeeds in reports

I need to take a report text file that is output from vendor software and there are some pages which have less then the normal amount of lines. I need to add these missing line feeds as there is a merge program that reads this file in fixed character and line mode template to output the final PDF... (6 Replies)
Discussion started by: rnygren
6 Replies

4. Programming

Static in Qt c++ Embedded Python

i have a problem in Use static variables in Qt C++ under CentOS 5.5 i need to pass a variable from GUI to class all function are static. it always give me that error error: undefined reference to strChar class QPython : public QObject { private: public: QString strChar; static PuObject*... (1 Reply)
Discussion started by: HanyM.Magdy
1 Replies

5. UNIX for Dummies Questions & Answers

Embedded systems

Hi, I dont know whether it is the right space to put it... but didnt found related Embedded. I want to start learning Embedded systems in Unix, It would be greatly appreciable if someone could help me to start off .... Thanks (0 Replies)
Discussion started by: Deei
0 Replies

6. Shell Programming and Scripting

Escaping embedded variables

I'm running into a problem with a differential backup script written in GNU Bash 3.0 - the following stripped down code demonstrates the problem quite nicely. $ DATE="last tuesday" $ date --date="$DATE" Tue Jan 6 00:00:00 PST 2009 So far so good. $ CMD="date --date=\"$DATE\"" $... (6 Replies)
Discussion started by: vertigo23
6 Replies

7. Shell Programming and Scripting

Removing Embedded Newline from Delimited File

Hey there - a bit of background on what I'm trying to accomplish, first off. I am trying to load the data from a pipe delimited file into a database. The loading tool that I use cannot handle embedded newline characters within a field, so I need to scrub them out. Solutions that I have tried... (7 Replies)
Discussion started by: bbetteridge
7 Replies

8. Shell Programming and Scripting

Problems with Embedded IF-else

Hi, I am putting the finishing touches on a shell script. I have the following which works FINE: if ] && ] then /bin/mail -s "Illegal Loggon Attempts on MAIL" sysadmin@ghf.com < final_email.tmp fi However, I need to make several else clauses and the interpreter complains... (1 Reply)
Discussion started by: mojoman
1 Replies

9. Shell Programming and Scripting

Embedded list? Is this possible

I need to write a script that maintains many directories. I was wondering is there is a way to create a list of the directories inside a script so that you can then use “while read line” to perform different commands for each directory. Something like this #!/bin/sh MYLIST: /dir1 /dir2... (1 Reply)
Discussion started by: zasxes
1 Replies

10. Programming

Embedded programming

Anyone know any good sources (books, urls, etc) for learning embedded programming, for example with Tornado from Wind River? (3 Replies)
Discussion started by: TioTony
3 Replies
Login or Register to Ask a Question