nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

UNIX Shell Change the EOL (\n newline) by nothing - remove new line

This is a discussion on UNIX Shell Change the EOL (\n newline) by nothing - remove new line within the Shell scripting forums, part of the Development/Scripting category; I have a txt file like this: hello, hi, word3, and I would like to get only one line, what ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 05-13-2008, 08:03 PM
Junior Member
User
 
Join Date: May 2008
My distro: fedora
Posts: 15
permalac is on a distinguished road
Default UNIX Shell Change the EOL (\n newline) by nothing - remove new line

I have a txt file like this:

hello,
hi,
word3,



and I would like to get only one line, what would you do?


sed 's/$//g' whas my chance, and did not work.


thanks .
Reply With Quote
  #2 (permalink)  
Old 05-13-2008, 08:40 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
My distro: Any distro with shell
Posts: 840
nixcraft is an unknown quantity at this point
Default

Sorry, but I don't get your question. Can you provide more details?
__________________
Vivek | My personal blog
Linux Evangelist
Play hard stay cool
Reply With Quote
  #3 (permalink)  
Old 05-13-2008, 09:07 PM
Junior Member
User
 
Join Date: May 2008
My distro: fedora
Posts: 15
permalac is on a distinguished road
Default sed perl shell command to remove newline (\n) from a file

sure.



I have this :

Quote:
word1,
word2,
word3,
And I want this:

Quote:
word1,word2,word3,

Last edited by nixcraft; 05-14-2008 at 01:05 AM.
Reply With Quote
  #4 (permalink)  
Old 05-14-2008, 12:56 AM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
My distro: Any distro with shell
Posts: 840
nixcraft is an unknown quantity at this point
Default

Try following shell script
Code:
#!/bin/bash
INPUT="/path/to/file"
while read line
 do
 echo -n $line
done < $INPUT
You can also try tr
Code:
tr -d '\n\' < /path/to/file
Perl version
Code:
perl -e 'while (<>) { if (! /\|$/ ) { chomp; } print ;}' </path/to/input/file
GNU sed version (may not work with UNIX / BSD sed):
Code:
sed ':a;N;$!ba;s/\n//g' < /path/to/file
Use any one of the above method
__________________
Vivek | My personal blog
Linux Evangelist
Play hard stay cool

Last edited by nixcraft; 05-14-2008 at 01:05 AM.
Reply With Quote
  #5 (permalink)  
Old 05-14-2008, 07:11 PM
Junior Member
User
 
Join Date: May 2008
My distro: fedora
Posts: 15
permalac is on a distinguished road
Default

OOOK, many thanks.

I like the sed one, .
Reply With Quote
  #6 (permalink)  
Old 05-14-2008, 11:03 PM
agn agn is offline
Member
User
 
Join Date: Feb 2008
My distro: OpenBSD/FreeBSD/Debian/Fedora/RHEL
Posts: 69
agn is on a distinguished road
Default

Code:
paste -s -d '\0' file
Reply With Quote
Reply

Bookmarks

Tags
linux , perl , remove new line , remove \n , sed , shell script , unix

Thread Tools
Display Modes

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


Similar Threads

Thread Thread Starter Forum Replies Last Post
unix shell on windows xp chiku Solaris/OpenSolaris 4 03-07-2008 03:17 PM
HPUX Unix comparing 2 large files line by line raj HP-UX 1 02-11-2008 05:20 PM
Linux UNIX SFTP in a Shell Script Nishanthhampali Shell scripting 1 01-30-2008 01:16 PM
How to change the login shell for Linux user chimu Getting started tutorials 0 01-26-2007 07:20 PM
Shell script to change folder directory owner after restore marinm Shell scripting 5 01-23-2007 12:53 PM


All times are GMT +5.5. The time now is 09:25 PM.


Powered by vBulletin® Version 3.7.2 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30