The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Parsing of file for Report Generation (String parsing and splitting) umar.shaikh Shell Programming and Scripting 8 03-02-2009 01:38 AM
Parsing file, yaml file? Extracting specific sections Rhije Shell Programming and Scripting 3 01-22-2009 06:36 PM
Script for parsing details in a log file to a seperate file pingnagan UNIX for Dummies Questions & Answers 2 11-13-2008 12:21 PM
need help in Parsing a CSV file and generate a new output file vkr Shell Programming and Scripting 15 08-01-2008 08:33 AM
Finding & Moving Oldest File by Parsing/Sorting Date Info in File Names nikosey Shell Programming and Scripting 6 07-30-2008 10:46 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-20-2009
phil_heath phil_heath is offline
Registered User
  
 

Join Date: May 2009
Posts: 54
Parsing a file

Hi,

I have a file that looks like this:

Code:
>JANE:BOB_JOE.6 ELLEN, Barg c452 5691-6524
YINKHJHJHJGJGHGHGHGHGMNJHJHKJKJHJHJHJHJHJHJHJHJHJHJHJHJ
>JANE:BOB_JOE.6 DOOR, Yak c459 5691-6524 REVERSE
YINKHJHJHJGJGHGHGHGHGMNJHJHKJKJHJHJHJHJHJHJHJHJHJHJHJHJIIIIIIIIIIIIIIIIIIIIII

Basically I only want it to print ELLEN, Barg c452 5691-6524 and DOOR, Yak c459 5691-6524 REVERSE into a seperate file.

Phil

Last edited by vgersh99; 07-20-2009 at 04:44 PM.. Reason: code tags, PLEASE!
  #2 (permalink)  
Old 07-20-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
Code:
sed -n '/^>/s/^>[^ ][^ ]* *\(.*\)/\1/p' myFile > myNewFile


---------- Post updated at 03:44 PM ---------- Previous update was at 03:44 PM ----------

To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
  #3 (permalink)  
Old 07-20-2009
anchal_khare anchal_khare is offline
Registered User
  
 

Join Date: Jun 2007
Location: Mumbai,India
Posts: 325
Quote:
Originally Posted by phil_heath View Post
Hi,

Basically I only want it to print ELLEN, Barg c452 5691-6524 and DOOR, Yak c459 5691-6524 REVERSE into a seperate file.

Phil
one way:
Code:
awk '/^>/ print {$2,$3,$4,$5,$6}' myfile
  #4 (permalink)  
Old 07-20-2009
durden_tyler's Avatar
durden_tyler durden_tyler is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2009
Posts: 534
And here's a solution in Perl -

Code:
$ 
$ cat data.txt
>JANE:BOB_JOE.6 ELLEN, Barg c452 5691-6524
YINKHJHJHJGJGHGHGHGHGMNJHJHKJKJHJHJHJHJHJHJHJHJHJHJHJHJ
>JANE:BOB_JOE.6 DOOR, Yak c459 5691-6524 REVERSE
YINKHJHJHJGJGHGHGHGHGMNJHJHKJKJHJHJHJHJHJHJHJHJHJHJHJHJIIIIIIIIIIIIIIIIIIIIII
$ 
$ perl -lne '/^>[^ ]+ (.*)/ && print $1' data.txt
ELLEN, Barg c452 5691-6524
DOOR, Yak c459 5691-6524 REVERSE
$
tyler_durden
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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




All times are GMT -4. The time now is 08:49 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0