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
extracting text and reusing the text to rename file JohnDS UNIX for Dummies Questions & Answers 7 02-05-2009 03:55 AM
Extracting specific text from a file rahulkav Shell Programming and Scripting 8 10-22-2008 10:34 AM
extracting a set of strings from a text file Deanne Shell Programming and Scripting 2 09-20-2007 11:31 PM
Extracting information from text fields. spindoctor UNIX for Dummies Questions & Answers 24 06-09-2007 01:17 PM
extracting last paragraph from a text uvrakesh Shell Programming and Scripting 1 04-24-2007 05:36 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-06-2009
krabu krabu is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 44
Extracting Text

Hi,
I have a file like that

No seq Text
269091 123443124 how are slkslks, serial no is 042890000 and pincode is
090001223433454
269091 123443124 how are slkslks, Sr/no is 0428901 and 14 digits are is
040001223433451.

I want to extract serial no or Sr and pincode or 14 digits. Both occur in
the file. outup should be like that

042890000 090001223433454
0428901 040001223433451

Thanks in advance.
  #2 (permalink)  
Old 04-06-2009
pmm pmm is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 50
Assuming above is 2 records (i.e. not 4 records):
269091 123443124 how are slkslks, serial no is 042890000 and pincode is 090001223433454
269091 123443124 how are slkslks, Sr/no is 0428901 and 14 digits are is 040001223433451

Code:
nawk -F" is " ' { split($2,A," "); split($3,B," "); print A[1] " " B[1] } ' file
  #3 (permalink)  
Old 04-07-2009
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,390
Quote:
Originally Posted by pmm View Post
Assuming above is 2 records (i.e. not 4 records):
guys the pattern is in two different lines not in one line
try this
Code:
 
sed -n -e 'N;H' -e 's/\n/ /p' filename|sed -e 's/\(.*[no|Sr] is\)\(.*\)\(and .*is\)\(.*\)/\2\4/g'
  #4 (permalink)  
Old 04-07-2009
sai21 sai21 is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 27
sed 's/\(.*no is\) \(.* \)\(and .* is\)\(.*\)/\2\4/g' filename
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 08:27 PM.


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