LinuxQuestions.org
Register a domain and help support LQ
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 07-29-2009, 08:08 AM   #1
tatoosh
LQ Newbie
 
Registered: Jul 2009
Posts: 13

Rep: Reputation: 1
add text to end of line?


I had to do this:

i want to add a text of each line, but not when the word REJECTED is the last word in the line.

the text is (tab = user tabulator)
<tab> OK

i know i can add with 'sed' the text but how to check if the line ends with 'REJECTED' ?
 
Old 07-29-2009, 08:30 AM   #2
joeBuffer
Member
 
Registered: Jul 2009
Distribution: Ubuntu 9.04
Posts: 328

Rep: Reputation: 42
/REJECTED$/ will match a line ending with REJECTED, the dollar sign being the end of the line ...
 
Old 07-29-2009, 08:32 AM   #3
jdkaye
LQ Guru
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,464

Rep: Reputation: Disabled
This wouldn't be homework, would it?
jdk
 
Old 07-29-2009, 08:36 AM   #4
centosboy
Senior Member
 
Registered: May 2009
Location: london
Distribution: centos5
Posts: 1,137

Rep: Reputation: 116Reputation: 116
Quote:
Originally Posted by tatoosh View Post
I had to do this:

i want to add a text of each line, but not when the word REJECTED is the last word in the line.

the text is (tab = user tabulator)
<tab> OK

i know i can add with 'sed' the text but how to check if the line ends with 'REJECTED' ?
Code:
perl -pi.bak -e 's/oldstring$/newstring/g'  file

perl in line edit. .bak for saving orig file
 
Old 07-29-2009, 08:39 AM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
sed '/REJECTED$/!s/$/new ending/' filename > newfilename
 
Old 07-29-2009, 08:43 AM   #6
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Quote:
Originally Posted by jdkaye View Post
This wouldn't be homework, would it?
jdk
I guessed "no" because of posting history. Of course it could ALL be homework.......
 
Old 07-30-2009, 08:21 AM   #7
tatoosh
LQ Newbie
 
Registered: Jul 2009
Posts: 13

Original Poster
Rep: Reputation: 1
thanks for helping. i used another way so solve my problem.
 
Old 07-31-2009, 04:15 AM   #8
centosboy
Senior Member
 
Registered: May 2009
Location: london
Distribution: centos5
Posts: 1,137

Rep: Reputation: 116Reputation: 116
Quote:
Originally Posted by tatoosh View Post
thanks for helping. i used another way so solve my problem.

share then...after all, you did ask for help..
 
Old 07-31-2009, 04:28 AM   #9
tatoosh
LQ Newbie
 
Registered: Jul 2009
Posts: 13

Original Poster
Rep: Reputation: 1
i used not this way. anyway - here is my part of script for the question:
it cleans my postmap file - so i dont need the "reject" thing i asked for.

Code:
#clean up 
 sed -e 's/[ \t]*OK/ \tOK/' $1 > $temp_file
 mv $temp_file $1 -f 
 sed -e 's/[ \t]*OK[ ]/ \tOK/' $1 > $temp_file
 mv $temp_file $1 -f 
 sed -e 's/[ \t]*Ok/ \tOK/' $1 > $temp_file
 mv $temp_file $1 -f 
#lowercase <MAILLIST>
 cat $1 |  tr "[A-Z]" "[a-z]" > $temp_file
 mv $temp_file $1 -f
 
  


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
Sed append text to end of line if line contains specific text? How can this be done? helptonewbie Linux - Newbie 4 10-23-2013 02:48 PM
Deleting empty line at end of text file in BASH human2.0 Linux - General 8 04-01-2009 03:44 AM
Attempting to append a line of text to the end of the previous line market_garden Linux - General 4 12-11-2008 12:37 PM
How to add a text to first line of a text file? oskeewow Linux - Newbie 6 04-23-2008 01:40 PM
Shell scripting: How to add characters at the end of the line Micro420 Programming 7 05-18-2007 02:56 AM


All times are GMT -5. The time now is 01:43 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration