The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to insert carriage return before line feed? huey ing Shell Programming and Scripting 2 08-05-2005 01:22 PM
Removing Carriage Return and or line feed from a file tbone231 Shell Programming and Scripting 1 02-18-2005 04:37 PM
Remove a carriage return at end of variable flagship99 UNIX for Dummies Questions & Answers 5 11-17-2004 06:39 PM
carriage return/line feeds pitstop Shell Programming and Scripting 4 11-24-2003 03:47 PM
Regex to pick up name from the following including carriage return at end of the line Shakey21 Shell Programming and Scripting 3 07-18-2002 08:27 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-30-2007
shash shash is offline
Registered User
  
 

Join Date: Jan 2007
Posts: 21
To remove carriage return between the line

Hi,

I have a situation where I need to remove the carriage return between the lines.

For.eg.

The input file:

1,ad,"adc
sdfd",edf
2,asd,"def
fde",asd

The output file should be

1,ad,adc sdfd,edf
2,asd,def fde,asd

Thanks
Shash
  #2 (permalink)  
Old 07-30-2007
awk awk is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 134
awk '/^[1-9]/{print ""}
{gsub("\"", "")
printf"%s,", $0}
END{print ""}' <<EOF | sed 's/,$//'
1,ad,"adc
sdfd",edf
2,asd,"def
fde",asd
EOF

1,ad,adc,sdfd,edf
2,asd,def,fde,asd
  #3 (permalink)  
Old 07-30-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
If 'awk' is not required:
Code:
while read mLine1
do
  read mLine2
  echo ${mLine1}${mLine2}
done < input_file
  #4 (permalink)  
Old 07-31-2007
shash shash is offline
Registered User
  
 

Join Date: Jan 2007
Posts: 21
Thanks awk. It works and I have changed it to replace a space instead of comma in place of the carriage return.

Thanks for the reply Shell_Life, but some lines will not have the carriage return.
  #5 (permalink)  
Old 07-31-2007
shash shash is offline
Registered User
  
 

Join Date: Jan 2007
Posts: 21
I am having problems if I use the files as my input.

The code I'm using is as follows:

awk '/^[1-9]/{print ""}
{gsub("\"", "")
printf"%s ", $0}
END{print ""}' book2.csv | sed 's/,$//' > book3.csv


book2.csv contains data as follows:

1,ad,"adc
sdfd",edf
2,asd,"def
fde",asd
3,def,fde

The output I'm getting as book3.csv

,ad,adc sdfd,edf
,asd,def fde,asd
3,def,fde

1 & 2 values are missing.

Thanks
Shashi
  #6 (permalink)  
Old 07-31-2007
shash shash is offline
Registered User
  
 

Join Date: Jan 2007
Posts: 21
Well Shell_life code do works.. Thanks
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:23 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0