LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
LinkBack Search this Thread
Old 08-13-2012, 10:50 AM   #1
anshaa
LQ Newbie
 
Registered: Aug 2012
Posts: 12

Rep: Reputation: Disabled
Need to replace '\n' with '\n~'


Need to replace '\n' with '\n~'
input
test|123|abcd
te12|258|abdk


output
test|123|abcd~
te12|258|abdk~
 
Old 08-13-2012, 11:09 AM   #2
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora
Posts: 2,299

Rep: Reputation: 395Reputation: 395Reputation: 395Reputation: 395
are you wanting to automate this or are you editing a script?
 
Old 08-13-2012, 11:20 AM   #3
cbtshare
Member
 
Registered: Jul 2009
Posts: 561

Rep: Reputation: 42
this sounds like homework...can you please show us what you did so far and we'll be happy to assist.
 
Old 08-13-2012, 11:29 AM   #4
suicidaleggroll
Senior Member
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 2,426

Rep: Reputation: 890Reputation: 890Reputation: 890Reputation: 890Reputation: 890Reputation: 890Reputation: 890
Your requirements and your example don't match. Putting the tilde after the newline would make it the first character on the second line, not the last character on the first line.

Code:
test|123|abcd
te12|258|abdk
would become

Code:
test|123|abcd
~te12|258|abdk
~
 
Old 08-14-2012, 12:38 AM   #5
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,205

Rep: Reputation: 1797Reputation: 1797Reputation: 1797Reputation: 1797Reputation: 1797Reputation: 1797Reputation: 1797Reputation: 1797Reputation: 1797Reputation: 1797Reputation: 1797
+1 to suicidaleggroll
 
Old 08-14-2012, 06:49 AM   #6
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946
As in most line editing, the usual tools are sed or awk. In this particular case sed is probably the better tool.

I'm not going to give you the solution, though. You should be able to figure it out yourself with a tiny bit of research.

Here are a few useful sed references:
http://www.grymoire.com/Unix/Sed.html
http://sed.sourceforge.net/grabbag/
http://sed.sourceforge.net/sedfaq.html
http://sed.sourceforge.net/sed1line.txt
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Sed replace Help replace for (<a> guessity Linux - Newbie 1 11-18-2011 09:05 AM
need to replace RH 9 ? juanb Linux - General 5 01-30-2004 08:32 PM
Replace HD CloudBuilder Linux - Hardware 1 11-03-2003 01:26 AM
problem in perl replace command with slash (/) in search/replace string ramesh_ps1 Red Hat 4 09-10-2003 01:04 AM
Is it possible to replace sh? J_Szucs *BSD 12 08-14-2002 10:50 PM


All times are GMT -5. The time now is 03:29 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration