Using grep to select data from file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Using grep to select data from file
# 1  
Old 05-24-2013
Using grep to select data from file

Hello all,

Once again I need to call upon the masters for help. I have a file called endpoint_data. IN that file I have groups of endpoints. However all I need from the file is this....

Code:
ENDPOINT NAME      = SIPWOODSBC
SIG PRI FQDN/IP ADDRESS/DOMAIN NAME = 10.xxx.xxx.xxx
SIG SEC FQDN/IP ADDRESS = 10.xxx.xxx.xxx

Im trying to figure out a command that will grep the file for these lines and display them neatly in a file together. Any help would be greatly appreciated.Smilie

Last edited by joeyg; 05-24-2013 at 11:14 AM..
# 2  
Old 05-24-2013
What have you figured so far?
# 3  
Old 05-24-2013
You could help your chances for an answer

You need to provide better titles to questions, and to show more detail in your question. You are kind of showing desired output (I think) but no input.
Also, as Scott asked... what have you tried?
# 4  
Old 05-24-2013
IM sorry, Im a beginner.


I have a file, with groups of data in it.

For example, each group looks like this within the file...
Code:
CONTACT ID         = 5346                 ENDPOINT NAME      = 8888888888
ENDPOINT ID        = 673                  HOST ADDRESS       = 10.xxx.xxx.xxx
PORT               = 5060                 TYPE               = NONE
TRANSPORT TYPE     = UDP                  MEDIA TYPE         = AUDIO
PRIORITY           = 0.0                  TIME TO LIVE       = 3600
REG EXPIRATION TIME= Fri May 24 10:18:49 2013
PRI ADDRESS RECORD = 
CONTACT URI        = sip:8888888888@10.xxx.xxx.xxx:5060;transport=udp
REGISTRATION TYPE  = REGISTERED
ENDPOINT ALIAS NAME= 8888888888
CONTACT NUMBER     = 1                    WEIGHT             = 0

Now, Id like to grep specific lines from this data, and put them together just like this..

Code:
ENDPOINT NAME= 8888888888   HOST ADDRESS  = 10.xxx.xxx.xxx

This is all I am trying to accomplish.

So far, Ive done this..

Code:
grep "ENDPOINT NAME" endpointdata >data1
grep "HOST ADDRESS" endpointdata >data2
paste data1 data2 > data3

This seems to work, but its messy. Was hoping for some better ways to learn.

Last edited by Scott; 05-24-2013 at 10:48 AM.. Reason: Code tags
# 5  
Old 05-24-2013
From what you show above, you could:-
Code:
echo "ENDPOINT NAME      = SIPWOODSBC
SIG PRI FQDN/IP ADDRESS/DOMAIN NAME = 10.xxx.xxx.xxx
SIG SEC FQDN/IP ADDRESS = 10.xxx.xxx.xxx"

....or if this is in a file:-
Code:
cat filename

You have not given me anything else to consider or any output from failed attempts.

Do you have a sample of input perhaps?



Robin
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Using grep to select specific patterns in text file?

How do I use grep to select words that start with I or O, end in box, and contain at least one letter in between them? the text file mailinfo.txt contains Inbox the Inbox Is a match box Doesn't match INBOX Outbox Outbox1 InbOX Ibox I box If the command works correctly it... (4 Replies)
Discussion started by: steezuschrist96
4 Replies

2. UNIX for Dummies Questions & Answers

Select last update data based on file name

Hi All, I need to remove all files except the most update data based on date on filename Input data_AIDS_20150312.txt data_AIDS_20150311.txt data_AIDS_20150411.txt data_AIDS_20140312.txt the most updated data is data_AIDS_20150411.txt, so I'll remove other files. My expected output... (3 Replies)
Discussion started by: radius
3 Replies

3. Shell Programming and Scripting

awk - mixed for and if to select particular lines in a data file

Hi all, I am new to AWK and I am trying to solve a problem that is probably easy for an expert. Suppose I have the following data file input.txt: 20 35 43 20 23 54 20 62 21 20.5 43 12 20.5 33 11 20.5 89 87 21 33 20 21 22 21 21 56 87 I want to select from all lines having the... (4 Replies)
Discussion started by: naska
4 Replies

4. Shell Programming and Scripting

Grep to isolate a text file line and Awk to select a word?

I am looking at using grep to locate the line in the text file and them use awk to select a word or words out of it. I know awk needs -v to allow a variable to be used, but also needs -F to allow the break up of the sentence and allow the location of separate variables. $line = grep "1:" File |... (8 Replies)
Discussion started by: Ironguru
8 Replies

5. Shell Programming and Scripting

Select data from a file

Hi , I want to select data from a file .the datas in a file will be in both upper and lower case. can able to select particular data using awk. file is like Ram Selva 24332 UNIXTEAM Karthi Siva 43322 UNIXTEAM In read if i enter selva as lowercase its not displaying result. (9 Replies)
Discussion started by: boopal
9 Replies

6. Shell Programming and Scripting

Extracting specific lines of data from a file and related lines of data based on a grep value range?

Hi, I have one file, say file 1, that has data like below where 19900107 is the date, 19900107 12 144 129 0.7380047 19900108 12 168 129 0.3149017 19900109 12 192 129 3.2766666E-02 ... (3 Replies)
Discussion started by: Wynner
3 Replies

7. Shell Programming and Scripting

select data from oracle table and save the output as csv file

Hi I need to execute a select statement in a solaris environment with oracle database. The select statement returns number of rows of data. I need the data to be inserted into a CSV file with proper format. For that we normally use "You have to select all your columns as one big string,... (2 Replies)
Discussion started by: rdhanek
2 Replies

8. Shell Programming and Scripting

i want to grep some data from other file

helo all i have 2 files. and i want to grep the contents of first file from the 2nd file. but these files are too large contaning lacks of lines . i'm using for loop but it takes so moch times . is there any other sol. i'm using this code " for var in `cat succ_migrated` do grep $var... (4 Replies)
Discussion started by: dodasajan
4 Replies

9. Shell Programming and Scripting

grep data and add to file

Hey, i need to write a bash program that can run through a liste of files and then pick up the last access time and modification times and then write them to a file. If anyone has done something like this before, please help me. Thanks (5 Replies)
Discussion started by: nbananda
5 Replies

10. Shell Programming and Scripting

Pipe Data From Grep Into A File

I am somewhat of a novice at unix scripting and I need a little help. Here is what im trying to do: I am trying to figure out how to pipe the following grep results into a file. /source/programs: grep "WSBL020" W* WBMB991.cbl: COPY WSBL020. WDCB003.cbl: COPY... (4 Replies)
Discussion started by: katinicsdad
4 Replies
Login or Register to Ask a Question