Awk error for joining records with CR/newline


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk error for joining records with CR/newline
# 1  
Old 09-25-2005
Awk error for joining records with CR/newline

Is there any way to remove carriage retuns between the records?

These carriage returns are created in an excel cell by using Alt+enter, this is similar to new line...

We have input records separated by TABS and have carriage returns as below:

123 456 789 ABC "1952.00" 678 "abcdef
ghik
lmno"

Above we have 7 fields, notice that the 7th field in the records has carriage returns and make it into records...

I need to remove the carriage returns and make it look like below:

123 456 789 ABC "1952.00" 678 "abcdef ghik lmno"

I was given the below answer in the forum...

and this works for smaller record, this code gives an awk error "more than 199 fields"....

Code: filename JoinRecord.awk
{ record = record $0
# If number of quotes is odd, continue reading record.
if ( gsub( /"/, "&", record ) % 2 )
{ record = record " "
next
}
}
{ print record
record = ""
}


The above script works fine for small record. I recently got awk error something like more than 199 fields... I'm currently using awk -f JoinRecord.awk inputfilename > outputfilename on HP-UX 11.0 box...

we also don't have nawk on HP-UX 11.0.

Is there any way to overcome the above awk error?

Thanks in advance.

AC
# 2  
Old 09-27-2005
You could try converting the awk to perl using a2p
# 3  
Old 09-27-2005
Thanks a lot! It works great...
# 4  
Old 10-06-2005
Can you send me the sample code that worked for u

Can you please send me the sample code that worked for u.
extracting 200th field
# 5  
Old 10-06-2005
I'm not extracting the 200th field here.
# 6  
Old 10-06-2005
By the the original code is in the above posting. Only thing I did was to convert the awk to perl script as suggeted by Ygor. And that works great!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Issue with awk when joining two files when field has '-' hyphen

Dear Community; I need to join two files but I am facing issues. 1st file has multiple columns. Primary (1st) columns has unique values. There are other columns out of which some has non-ascii characters as well (other language). Example File below: 1-1001JRL,BiRecurring... (5 Replies)
Discussion started by: mystition
5 Replies

2. Shell Programming and Scripting

awk joining multiple lines based on field count

Hi Folks, I have a file with fields as follows which has last field in multiple lines. I would like to combine a line which has three fields with single field line for as shown in expected output. Please help. INPUT hname01 windows appnamec1eda_p1, ... (5 Replies)
Discussion started by: shunya
5 Replies

3. Shell Programming and Scripting

Joining files using awk not extracting all columns from File 2

Hello All I'm joining two files using Awk by Left outer join on the file 1 File 1 1 AA 2 BB 3 CC 4 DD File 2 1 IND 100 200 300 2 AUS 400 500 600 5 USA 700 800 900 (18 Replies)
Discussion started by: venkat_reddy
18 Replies

4. Shell Programming and Scripting

Joining broken lines with awk or perl

Hi, I have a huge file with sql broken statements like: PP3697HB @@@@0 <<<<<<Record has been deleted as per PP3697HB>>>>>> FROM sys.xtab_ref rc,sys.xtab_sys f,sys.domp ur WHE RE rc.milf = ur.milf AND rc.molf = f.molf AND ur.dept = 'SWIT'AND ur .department = 'IND' AND share = '2' AND... (4 Replies)
Discussion started by: som.nitk
4 Replies

5. Shell Programming and Scripting

Error awk: 0602-592 cannot contain a newline character

Hi guys, I'am new at this forum as well as with unix. currently iam trying to create a unix script that will write certain string of words into a file depending on certain conditions apparently i am having problems in terms of writing into the file using the awk. it returns an error ... (0 Replies)
Discussion started by: jihmantiquilla
0 Replies

6. Shell Programming and Scripting

Remove \n <newline> character inside the records.

Hi, In my file, I have '\n' characters inside a single record. Because of this, a single records appears in many lines and looks like multiple records. In the below file. File 1 ==== 1,nmae,lctn,da\n t 2,ghjik,o\n ut,de\n fk Expected output after the \n removed File 2 =====... (5 Replies)
Discussion started by: machomaddy
5 Replies

7. Shell Programming and Scripting

Joining lines in a text file using AWK or SED

Hi All I'm struggling a bit here :( I need a way of joining lines contained in a text file. I've seen numerous SED and AWK examples and none of them seem to be working for me. The text file has 4 lines: DELL1427 DOC 30189342 79 Now bear with me on this one as I'm actually... (4 Replies)
Discussion started by: huskie69
4 Replies

8. Shell Programming and Scripting

awk joining lines

Hello, I'm trying to write a piece of code in awk, which should be able recognize by some regexps two lines and then join them together (maybe write them without \n would be enough, I don't know).. the thing is that every line in the file i'm working with starts with some number, for example: ... (4 Replies)
Discussion started by: midin
4 Replies

9. Shell Programming and Scripting

Joining Two Files Using Awk

Hi All, I am new to awk program. But i have got some assignment on awk. The problem is: i have two files file1 and file2. Both files have same structure. First i have to join both files on filed1,field2 and field3 and then for matching records i want to perform some calculation like:... (1 Reply)
Discussion started by: Jeetuibm
1 Replies

10. Shell Programming and Scripting

Need Help with Joining Command or AWK

Hello. I have 2 files. File 1: 1692 @00000000201@00000205@20090402@000015000 1692 @00000000202@00000206@20090402@000010000 263157760@00000000401@00000201@20090402@000056250 510584583@00000000300@00000207@20090402@000030000 571764164@00000000100@00000128@20090402@000000500... (12 Replies)
Discussion started by: crazyhpux
12 Replies
Login or Register to Ask a Question