Extracting line from a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting line from a file
# 1  
Old 06-09-2009
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  
Old 06-09-2009
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  
Old 06-09-2009
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  
Old 06-10-2009
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  
Old 06-10-2009
Code:
echo '2009-05-06 19:48:46.857 INFO - [00001] [184] [AA][1q][ABC]' | nawk -F'[]]|[[]|INFO' '{print $1, "[" $(NF-1) "]"}'

# 6  
Old 06-10-2009
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  
Old 06-10-2009
Quote:
Originally Posted by imran721
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.
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. UNIX for Dummies Questions & Answers

problem with extracting line in file

My file looks like this and i need to only extract those with PDT_AP21_B and output it to another file. Can anyone help? Thanks. PDT_AP21_R,,, 11 TYS,,,,T17D1207230742TYO***T17DS,,C PDT_AP21_L,,,9631166650001 ,,,,T17D1207230903TYOTYST17DS ,,C... (3 Replies)
Discussion started by: Alyssa
3 Replies

3. UNIX for Dummies Questions & Answers

Extracting line1 from a file with certain file pattern in line 7

Hello there, I am new to unix and would like to do the following, hoping someone would give some guide, thanks in advance. Lets say i have a file like this: A w x y w x 0.1 B w x y w x 0.3 C w x y w x 0.7 D w x y w x 0.9 E w x y w x 0.2 So i would like to extract line 1 data where line... (2 Replies)
Discussion started by: seiksoon
2 Replies

4. Shell Programming and Scripting

error while extracting a line from a file based on identifier

here is the content of input file CREATE TABLE `bla bla bla` ( `allianceSiteId` int(11) DEFAULT NULL, `trunkGroupsId` int(11) DEFAULT NULL, `lastModified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, UNIQUE KEY `allianceSiteId`... (4 Replies)
Discussion started by: vivek d r
4 Replies

5. Shell Programming and Scripting

extracting line numbers from a file and redirecting them to another file

i have applied the following command on a file named unix.txt that contains the string "linux from the text" grep -n -i -w "linux from the text" unix.txt and the result is 5:Today's Linux from the text systems are split into various branches, developed over time by AT&T as well as various... (5 Replies)
Discussion started by: arindamlive
5 Replies

6. UNIX for Dummies Questions & Answers

Help: Sorting and extracting a line from a file

I was proposed with the following problem: The file 'numbers' contains a list of numbers. Write a command to place the largest one of those numbers in the file 'largest' (there should be nothing else in that file). Do not use the 'head' command in your answer. I think if i used the sort... (1 Reply)
Discussion started by: stava
1 Replies

7. Shell Programming and Scripting

Extracting a line in a text file

If my file looks like this…. 10 20 30 and I want to take each line individually and put it in a variable so it can be read later in it's on individual test statement, how can I do that? I guess what I'm asking is how can I extract each line individually. Thanks (5 Replies)
Discussion started by: terryporter51
5 Replies

8. Shell Programming and Scripting

extracting a line based on line number

i want to cut all the entries from the /etc/passwd file in which the uid is> 500 for this i was writing this ,m quiet new to all this.. scripting but on the 6th n 8th line ,, i hav to specify a line number .. to get the commnd working .. but i want to use variable i instead of that ,,... (2 Replies)
Discussion started by: narendra.pant
2 Replies

9. Shell Programming and Scripting

getting the line number by extracting a line

grep "KeyNotFoundException" weblogic.log After running this command the output is abcxyzexceptions.KeyNotFoundException: Person not found How to know ..what is the line number of the above string in the log file. (2 Replies)
Discussion started by: bishweshwar
2 Replies

10. Shell Programming and Scripting

Extracting specified line from a file using awk

Hi, I am just trying to extract a line at a time from a file using awk and can't yet extract even the first line using the following:- awk '/(^) && (NR==1)/ {print $1}' file1 Is there an obvious silly error here? Thanks (3 Replies)
Discussion started by: sirtrancealot
3 Replies
Login or Register to Ask a Question