The UNIX and Linux Forums  

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
Help: Sorting and extracting a line from a file stava UNIX for Dummies Questions & Answers 1 01-21-2009 12:07 AM
Extracting a line in a text file terryporter51 Shell Programming and Scripting 5 10-13-2008 07:34 PM
extracting a line based on line number narendra.pant Shell Programming and Scripting 2 09-20-2007 06:00 AM
getting the line number by extracting a line bishweshwar Shell Programming and Scripting 2 08-04-2007 10:46 AM
Extracting specified line from a file using awk sirtrancealot Shell Programming and Scripting 3 07-15-2006 03:09 PM

Closed Thread
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 06-09-2009
dwgi32 dwgi32 is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 22
Extracting line from a file

Hi,

I would like to extract a certain portion of sentences from a particular sentence i.e. to extract the last section embrace by []

input
[111] [SEND][abc.q][123456]
[122341] [SEND][ertgh.q][abcdef]

output
[123456]
[abcdef]

Please advice.

Cheers
  #2 (permalink)  
Old 06-09-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131

Code:
echo '[122341] [SEND][ertgh.q][abcdef]' | nawk -F'[]]|[[]' '{print "[" $(NF-1) "]"}'
echo '[122341] [SEND][ertgh.q][abcdef]' | sed 's/.*\(\[.*\]\)/\1/'
echo '[122341] [SEND][ertgh.q][abcdef]' | sed 's/.*\[/[/'


Last edited by vgersh99; 06-09-2009 at 02:56 PM..
  #3 (permalink)  
Old 06-09-2009
dwgi32 dwgi32 is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 22
Thank you very much

-----Post Update-----

Hi,

If i would extract the 1st section and last section of a line

input
2009-05-06 19:48:46.857 INFO - [00001] [184] [AA][1q][ABC]

output
2009-05-06 19:48:46.857 [ABC]

Cheers
  #4 (permalink)  
Old 06-10-2009
dwgi32 dwgi32 is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 22
Hi,

Need advise on the following:

to extract the first and last section of a lines.

input
2009-05-06 19:48:46.857 INFO - [00001] [184] [AA][1q][ABC]

output
2009-05-06 19:48:46.857 [ABC]

cheers
  #5 (permalink)  
Old 06-10-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131

Code:
echo '2009-05-06 19:48:46.857 INFO - [00001] [184] [AA][1q][ABC]' | nawk -F'[]]|[[]|INFO' '{print $1, "[" $(NF-1) "]"}'

  #6 (permalink)  
Old 06-10-2009
imran721 imran721 is offline
Registered User
  
 

Join Date: May 2009
Posts: 10
hi if would like to get the same kind of result with the output, can you guide me here please

<A>213444555</A><B>

I just want to get the phone number from the there from the file in between <A> and </A>

Thanks
  #7 (permalink)  
Old 06-10-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
Quote:
Originally Posted by imran721 View Post
hi if would like to get the same kind of result with the output, can you guide me here please

<A>213444555</A><B>

I just want to get the phone number from the there from the file in between <A> and </A>

Thanks
Please don't hijack other people threads - start a new thread.
Closed Thread

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 09:06 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