Extracting Text


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting Text
# 1  
Old 04-06-2009
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  
Old 04-07-2009
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  
Old 04-07-2009
sed 's/\(.*no is\) \(.* \)\(and .* is\)\(.*\)/\2\4/g' filename
# 4  
Old 04-07-2009
Quote:
Originally Posted by pmm
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'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Extracting lines from a text file based on another text file with line numbers

Hi, I am trying to extract lines from a text file given a text file containing line numbers to be extracted from the first file. How do I go about doing this? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

2. Shell Programming and Scripting

Extracting text from within a section of text using AWK

I have a command which returns the below output. How can I write a script to extract mainhost and secondhost from this output and put it into an array? I may sometimes have more hosts like thirdhost. I am redirecting this output to a variable. So I guess there should be a awk or sed command to... (7 Replies)
Discussion started by: heykiran
7 Replies

3. Shell Programming and Scripting

help extracting text from file

Hello I have a large file with lines beginning with 552, 553, 554, below is a small sample, I need to extract the data you can see below highlighted in bold from this file on the same location on every line and output it to a new file. Thank you in advance for any help 55201KL... (2 Replies)
Discussion started by: firefox2k2
2 Replies

4. Shell Programming and Scripting

Extracting Words from Text

Hi there, Unix Gurus Back in September last year you helped me find a way to extract the words in brackets in a textfile to a new one. In that case my textfile was made up of sentences containing an only bracketed word per sentence/line: 1. If the boss's son had been , someone would... (9 Replies)
Discussion started by: eldeingles
9 Replies

5. Programming

extracting text files

i m unable to extract data from one text files to different text files..i am able to concat two text files in d same file ---------- Post updated at 03:21 PM ---------- Previous update was at 03:16 PM ---------- i want a c program for it (2 Replies)
Discussion started by: asd123
2 Replies

6. Shell Programming and Scripting

Help with extracting text from a string

I dont know if I am making any sense here. But I need to do something like this. I have a variable that contains result from the svnlook command on a post-commit hook script. test=`/usr/bin/svnlook changed $REPOS -r $REV | grep "^A.*index.html$" and I get test=A ... (18 Replies)
Discussion started by: kminkeller
18 Replies

7. Shell Programming and Scripting

Extracting Text Between Quotes

I won't pretend. I am no bash, grep, awk or sed specialist but I have tried for a couple of days to extract something from a line in a file but have badly failed. There are just too may parenthesis, quotemarks, periods, etc. to trip me up, I think. I need to extract mail24b.someplace.net and... (6 Replies)
Discussion started by: Trapper
6 Replies

8. Shell Programming and Scripting

Extracting Text Between Two Words

Hi all! Im trying to extract a portion of text from a KML and put it into a new file. Im trying to get all of the points out of it, ignoring everything else so I need only the text between <Placement> and </Placement>. Is there a way to make it extract all instances of these points and not just... (2 Replies)
Discussion started by: Grizzly
2 Replies

9. UNIX for Dummies Questions & Answers

extracting text and reusing the text to rename file

Hi, I have some ps files where I want to ectract/copy a certain number from and use that number to rename the ps file. eg: 'file.ps' contains following text: 14 (09 01 932688 0)t the text can be variable, the only fixed element is the '14 ('. The problem is that the fixed element can appear... (7 Replies)
Discussion started by: JohnDS
7 Replies

10. Shell Programming and Scripting

extracting last paragraph from a text

Hi All, I want to extract last paragraph from a text for example aaaaa sadafsa sdfdsaf asfdsad asfdsfad asfdfsafd adfssas asdfsafdsa asfdasdfa sadfasdsaf i need the last paragraph how to do it using linux commands (1 Reply)
Discussion started by: uvrakesh
1 Replies
Login or Register to Ask a Question