Remove Carriage returns between strings in a field


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove Carriage returns between strings in a field
# 8  
Old 08-25-2005
Quote:
Originally Posted by acheepi
One more thing.. Could you tell me what it does excatly....
especially if ( gsub( /"/, "&", record ) % 2 )

Thanks in advance.

AC
We know that the record is incomplete if the number of quotes it contains isn't even. We use gsub to count the number of quotes in the line:
gsub( /"/, "&" )
replaces each quote with a quote (the & stands for whatever was matched by the regular expression) and returns the number of substitutions made. If that number is odd, i.e., if dividing by 2 gives a non-zero remainder, then the record is incomplete. So we tack on a space and jump back to the top of the input loop.
# 9  
Old 08-29-2005
Java Similar prob with \n newline

hi all,

i have csv file with three comma separated columns
i/p file
First_Name, Address, Last_Name
XXX, "456 New albany \n newyork, Unitedstates \n 45322-33", YYY\n
ZZZ, "654 rifle park \n toronto, canada \n 43L-w3b", RRR\n

is there any way i can remove \n (newline) from the second column
between the two double quotes"..."
# 10  
Old 08-30-2005
AC ( doubt in Remove \r)

u didn't mention where you are calling the file in the script
all u said is record?
what do u mean by record !
can u send me the whole script please , i have the similar situation
# 11  
Old 09-24-2005
awk limit for 199 fields

Quote:
Originally Posted by futurelet
Use Awk:

Code:
{ 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 some record. I recently got awk error something like more than 199 fields... I'm currently using awk -f {abovescript}.awk on HP-UX 11.0 box...

Is there any way to overcome the above awk error?

Thanks in advance.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove carriage returns from awk output

I'm on Linux version 2.6.32-696.3.1.el6.x86_64, using the Ksh shell. I'm working with the input file: John Daggett, 341 King Road, Plymouth MA Alice Ford, 22 East Broadway, Richmond VA Orville Thomas, 11345 Oak Bridge Road, Tulsa OK Terry Kalkas, 402 Lans Road, Beaver Falls PA Eric Adams,... (2 Replies)
Discussion started by: prooney
2 Replies

2. Shell Programming and Scripting

awk to remove field and match strings to add text

In file1 field $18 is removed.... column header is "Otherinfo", then each line in file1 is used to search file2 for a match. When a match is found the last four strings in file2 are copied to file1. Maybe: cut -f1-17 file1 and then match each line to file2 file1 Chr Start End ... (6 Replies)
Discussion started by: cmccabe
6 Replies

3. Shell Programming and Scripting

TR not removing carriage returns

I have a CSV with carriage returns in place of newlines. I am trying to use tr to remove them, but it isn't working. Academic year,Term,Course name,Period,Last name,Nickname 2012-2013,First Semester,English 12,4th Period,Arnold,Adam 2012-2013,First Semester,English 12,4th Period,Adams,Jim... (1 Reply)
Discussion started by: nextyoyoma
1 Replies

4. Shell Programming and Scripting

Awk to remove carriage return from 65th field

Hi, I have a pipe delimited file. There are around 700 columns in the file. The 65th column has carriage return which is causing read issue with our ETL process. I would like to replace the new line characters in 65th field with "nothing" i have return the following code and need help to... (7 Replies)
Discussion started by: pinnacle
7 Replies

5. Shell Programming and Scripting

Removal of carriage returns from a comma delimited file

Hi, I have a file which is having some carriage return in one of the field for which single line is coming in multiple lines. I want to combine all those multiple lines of that field into one line. Eg: Input: Id, Name, Location, Comments, Dept 2, John, US, I am from US. I... (5 Replies)
Discussion started by: mahish20
5 Replies

6. Shell Programming and Scripting

removing carriage returns in text file

Hi I have a text file that looks like this: A B C D E F G H I I want it to be reformatted to A;B;C; D;E;F; G;H;I; (4 Replies)
Discussion started by: coolnfunky
4 Replies

7. Shell Programming and Scripting

Replacing Carriage returns without loosing EOL

Hello, I have read a few threads on this subject and tried a few things out, but still come up short. There was one good example, then the last reply was something to the effect of 'Use Sed' & 'Read a book'... Well I read a bunch of online tutorials on sed, awk, tr, but still can't get the... (2 Replies)
Discussion started by: Majiktom
2 Replies

8. Shell Programming and Scripting

removing thousand of carriage returns using sed

I need to replace thousands of carriage returns/line breaks in a large xml file and with spaces. I hope to do so with a script, called, for example, "removeCRs." I would invoke this at the command line as ml5003$ sed -f /Users/ml5003/removeCRs oldFile > newFile The script, I presume, would... (4 Replies)
Discussion started by: ml5003
4 Replies

9. Shell Programming and Scripting

Removing carriage returns with sed

How do we delete all carriage returns after a particular string using sed inside a K Shell? e.g. I have a text file named file1 below: $ more file1 Group#=1 User=A Role=a1 Group#=2 User=B Role=a1 Role=b1 Group#=3 User=C Role=b1 I want the carriage returns to be delete on the... (12 Replies)
Discussion started by: stevefox
12 Replies

10. Shell Programming and Scripting

spaces and carriage returns in 'here documents'

As the title suggests, i am having some trouble figuring out how to pass spaces and carriage returns to a 'here document' ie #!/bin/bash /usr/local/install_script.sh <<SCRIPT yes no <pass carriage retun here> yes no <pass a space and then a carriage return here> exit SCRIPT any... (0 Replies)
Discussion started by: hcclnoodles
0 Replies
Login or Register to Ask a Question