Help with removing embedded linefeeds


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with removing embedded linefeeds
# 8  
Old 07-27-2011
bartus11 - any idea why this code does not remove linefeeds from the very first line?
# 9  
Old 07-27-2011
Can you post sample data that you are using, the output that you are getting and what is desired output?
# 10  
Old 07-27-2011
This is my sample file:

$ cat test3
123|aaa|a1|a2|a5|a6
222|bbb|b1|b2|b3|b4
333|ccc|c1|c2|c3|c4
444|ddd|d1|d2|d3|d4

I add line feeds to the 2nd line :
$ cat test3
123|aaa|a1|a2|a5|a6
222|bb
b|b1|b2|b3|b4
333|ccc|c1|c2|c3|c4
444|ddd|d1|d2|d3|d4

And the awk works fine:
$nawk -F"|" 'NF<6{ORS=" ";p=1}NF==1{p=1}NF==6&&p{printf "\n";ORS="\n";p=0}1' test3
123|aaa|a1|a2|a5|a6
222|bb b|b1|b2|b3|b4
333|ccc|c1|c2|c3|c4
444|ddd|d1|d2|d3|d4

Now I add line feeds to the 1st line as well

$ cat test3
123|aa
a|a1|a2|a5|a6
222|bb
b|b1|b2|b3|b4
333|ccc|c1|c2|c3|c4
444|ddd|d1|d2|d3|d4

Now awk does not remove linefeeds from 1st record:

$ nawk -F"|" 'NF<6{ORS=" ";p=1}NF==1{p=1}NF==6&&p{printf "\n";ORS="\n";p=0}1' test3
123|aa a|a1|a2|a5|a6 222|bb b|b1|b2|b3|b4
333|ccc|c1|c2|c3|c4
444|ddd|d1|d2|d3|d4

$


Thanks for your help.

Last edited by stayalive; 07-27-2011 at 01:05 PM.. Reason: Was a duplicate post
# 11  
Old 07-27-2011
Try:
Code:
awk -F"|" 'NF<6{ORS=" ";n+=NF;print}n==7{printf "\n";ORS="\n";n=0}NF==6' file

# 12  
Old 07-27-2011
That did not help.

$ cat test3
123|aaa|a1|a2|a5|a6
222|b
b
b|b1|b2|b3|b4
333|ccc|c1|c2|c3|c4
444|ddd|d1|d2|d3|d4

$ awk -F"|" 'NF<6{ORS=" ";n+=NF;print}n==7{printf "\n";ORS="\n";n=0}NF==6' test3
123|aaa|a1|a2|a5|a6
222|b b b|b1|b2|b3|b4 333|ccc|c1|c2|c3|c4 444|ddd|d1|d2|d3|d4 $
# 13  
Old 07-27-2011
OK, try this:
Code:
awk -F"|" 'NF<6{ORS=" ";n+=(NF-1);print}n==5{printf "\n";ORS="\n";n=0}NF==6' file

# 14  
Old 07-27-2011
yet another awk script to try...
Code:
awk -F\| '{l=l?l""$0:$0;if(split(l,a,"|")==6){print l;l=""}}' file

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