LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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-11-2008, 10:28 AM   #1
tekmann33
Member
 
Registered: Nov 2006
Posts: 188

Rep: Reputation: 30
grep question


I have a large text file that has the following information in it. This is just a snippet of it:

Code:
3|9|JF HEN||
4|9|J COATSWORTH||
7|3|JF CHO #88|#88|
11|3|JF CHO #41|#41|
23|4|JF CHO #11|#11|
32|5|J 001.96 SCH||
44|2|J 170 P KAL||
46|9|1978 CALDECOTT AWARD||
46|10|J 222 SPI||
64|5|J 551.6 PRI||
79|6|EJ SCH||
86|6|342 BIL||
88|5|J 342.73 MAE||
102|4|EJ WIL||
109|3|J 617.7 ALE||
117|6|EJ BRO||
118|5|J 363.7 FIF||
122|4|973.3 LOE||
129|4|J 385.097 FRA||
132|8|J 391 ROW||
137|5|J 641.09 PEN||
143|7|EJ GEO||
150|10|J 394.2649 GIB||
157|3|J 398 PER||
170|8|J 398.2 BRE||
171|11|BB BRE||
171|12|EJ BRE||
I want to do the following things:
1. edit out the double pipe " || " only at the end of the line and redirect that info to a new file.

2. Edit out any text only at the end of the line that is between a double pipe (example |#11| )and redirect that to a new file.
 
Old 08-11-2008, 11:22 AM   #2
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:
edit out the double pipe " || " only at the end of the line and redirect that info to a new file.
redirect what info to the new file??


What reference do you use for scripting? I strongly recommend "Bash Guide for Beginners"---free at http://tldp.org

To redirect something to a file, simply put this at the end of the command string: "> newfilename"

There are several ways to grab a specific string, eg:
grep -o string filename ##prints every occurrence of "string"

To get only the text inside the last set of "|"s:
sed -n 's/.*|\(.*\)|$/\1/p' filename
(Actually, this syntax yields what is inside the last pair of "|"s at the end of the line.) To match something not at the end of the line, some more tweaks are required.

Last edited by pixellany; 08-11-2008 at 11:25 AM.
 
  


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
grep question yawe_frek Programming 3 01-05-2008 07:07 AM
maybe a grep question: me210 Linux - Software 3 01-19-2007 12:13 PM
Question about Grep irfanhab Linux - Newbie 6 08-23-2004 02:57 PM
grep question vasanthraghavan Programming 3 04-23-2004 12:32 AM
grep question keyops Programming 2 04-09-2004 09:17 PM


All times are GMT -5. The time now is 04:11 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