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
  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/Pop!_OS
Posts: 2,983

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
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: 645

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
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
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
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,999

Rep: Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190
+1 to suicidaleggroll
 
Old 08-14-2012, 06:49 AM   #6
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
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



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

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