If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Search Character at the End Of Line?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-04-05, 18:03
old_farmer old_farmer is offline
Registered User
 
Join Date: Feb 2005
Posts: 19
Search Character at the End Of Line?

Does anyone know how to write a sed command that will delete all lines except lines ending with a particular character - the character is the bar |

Thanks a lot for your help!
Reply With Quote
  #2 (permalink)  
Old 02-04-05, 18:13
vgersh99 vgersh99 is offline
Registered User
 
Join Date: Apr 2004
Location: Boston, MA
Posts: 325
sed -ne '/|$/p' file
__________________
vlad
+-----------------------+
| #include <disclaimer.h> |
+-----------------------+
Reply With Quote
  #3 (permalink)  
Old 02-04-05, 18:49
old_farmer old_farmer is offline
Registered User
 
Join Date: Feb 2005
Posts: 19
Thank you for the reply. The command didn't seem to alter the file. I entered:

sed -ne '/|$/p' test.txt

Is that correct?

Thanks again
Reply With Quote
  #4 (permalink)  
Old 02-04-05, 18:56
vgersh99 vgersh99 is offline
Registered User
 
Join Date: Apr 2004
Location: Boston, MA
Posts: 325
that's correct!
make sure thare'e no spaces/tabs/etc AFTER the trailing pipe.
__________________
vlad
+-----------------------+
| #include <disclaimer.h> |
+-----------------------+
Reply With Quote
  #5 (permalink)  
Old 02-04-05, 19:11
old_farmer old_farmer is offline
Registered User
 
Join Date: Feb 2005
Posts: 19
oh I just realized that. So now I have to get rid of all blank spaces after the |

There are some spaces that I want to keep within the line so I can't remove all spaces. So I tried this but it doesn't work:

sed -ne '/| *//p' test.txt

Any suggestion?
Reply With Quote
  #6 (permalink)  
Old 02-04-05, 19:19
vgersh99 vgersh99 is offline
Registered User
 
Join Date: Apr 2004
Location: Boston, MA
Posts: 325
# this will get the lines trailing spaces AFTER the last pipe
sed -ne '/| *$//p' test.txt

#this will do the above AND remove the trailing spaces from the selected lines
sed -ne '/| *$/s/ *$//p' test.txt
Reply With Quote
  #7 (permalink)  
Old 02-04-05, 19:32
old_farmer old_farmer is offline
Registered User
 
Join Date: Feb 2005
Posts: 19
i used the first one that you wrote - it worked perfectly!

Thank you
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On