LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-16-2007, 08:29 AM   #1
divya_linux
LQ Newbie
 
Registered: Oct 2007
Posts: 2

Rep: Reputation: 0
How to add a new line in bash


Hi,

I was trying to write a script which replaces the 'spaces' of a text file with a 'new line' in bash.

Can anybody help me out with this.

Regards,
Divya
 
Old 10-16-2007, 08:56 AM   #2
b0uncer
LQ Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
You probably want to get familiar with sed (or with awk, but I think sed does better here), it should be easy with it. It's easy in C also, but that's probably not what you're looking for..
 
Old 10-16-2007, 09:46 AM   #3
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Code:
tr ' ' '\n' < file
 
Old 10-16-2007, 10:41 AM   #4
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
The tr program is designed to replace some list of characters with another list. For example, to replace all lower case "a" "b" and "c" characters with upper case versions, you would use the command (prints results to standard output):
Code:
tr 'abc' 'ABC' < input_file
tr accepts c-style escapes for example \t to mean tab, \n to mean newline. So you could do this to replace all spaces and tabs with newlines:
Code:
tr ' \t' '\n\n' < input_file
 
Old 10-17-2007, 09:07 AM   #5
divya_linux
LQ Newbie
 
Registered: Oct 2007
Posts: 2

Original Poster
Rep: Reputation: 0
thanx folks

that did the job...
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash shell script read file line by line. Darren[UoW] Programming 57 04-17-2016 06:07 PM
BASH: read every line in the files and use the line as parameters as another program tam3c36 Programming 10 12-07-2010 01:42 PM
Can I add this line to FSTAB ? kc5hwb Ubuntu 8 04-08-2007 02:51 PM
Bash: add date to output line blizunt7 Programming 7 11-10-2004 03:45 AM
Bash scripting - add a character to a line. welby Programming 1 01-14-2004 10:09 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration