[Solved] Extracting data from a determined file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] Extracting data from a determined file
# 1  
Old 09-20-2011
Java [Solved] Extracting data from a determined file

Hi guys,

How you doing?

Need some help with this .I got a file with this kind of information

SURVIVABLE PROCESSORS
Name Type IP Address Reg Act Translations Net
Updated Rgn

Gateway001 LSP 10.10.255.1 n 1

I need to extract the Ip and send to it to another file to get something like this.

10.10.255.1
10.10.255.2
10.10.255.3
etc
Bare in mind that the file i am manipulating can be different one time from another so i need to make the script work indepently of the lines of the files.

Any ideas on how to resolve this?

Thanks for your time I WOULD really aprreciated if nyone can help me,,Smilie


REX
# 2  
Old 09-20-2011
Code:
grep -E '(^|[[:space:]])[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*([[:space:]]|$)' file

---------- Post updated at 10:11 AM ---------- Previous update was at 10:11 AM ----------

Code:
egrep -o [0-9]+\.[0-9]+\.[0-9]+\.[0-9]+ filename

# 3  
Old 09-20-2011
Java itīs worked !!! but have nother doubt

Thanks buddy for your help .... Itīs worked for that case. Forgot to tell that the format file could be like this
Code:
SURVIVABLE PROCESSORS
 Record Name/            Type         Reg Act         Translations      Net
 Number  IP Address                                   Updated           Rgn

  1     S8300_LSP_Wich   LSP           y   n          22:00 9/19/2011   6  
         192.168.249.10                          
        No V6 Entry    
                                                 
  2     S8500_ESS_BldgE  ESS S         y   n          22:00 9/19/2011   1  
         192.168.237.10                          
        No V6 Entry    
                                                 
  3     Salina_LSP       LSP           y   n          22:00 9/19/2011   60 
         192.168.245.10                          
        No V6 Entry    
                                                 
  4     bcbshutchlsp     LSP           y   n          22:00 9/19/2011   150
         192.168.36.2                            
        No V6 Entry

and when i shoot your command this :
Code:
egrep -o [0-9]+\.[0-9]+\.[0-9]+\.[0-9]+ servers.txt

22:00 9/19
192.168.249.10
22:00 9/19
192.168.237.10
22:00 9/19
192.168.245.10
22:00 9/19
192.168.36.2

and i still need the format
Code:
192.168.249.10
192.168.237.10
192.168.245.10
192.168.36.2

To send it to another file ...Smilie

Could you help me to modify it?

Thanks for your support!!
RexSmilie

Last edited by Franklin52; 09-21-2011 at 08:36 AM.. Reason: Please use code tags for code and data samples, thank you
# 4  
Old 09-20-2011
Code:
sed -n 's/\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\).*/\1/gp' inputFile | sed 's/.* \([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\)/\1/g'

--ahamed
# 5  
Old 09-20-2011
If your file format is same, then you can use the below awk command.

Code:
 
$ nawk ' /^[0-9][0-9]/ ' test
192.168.249.10 
192.168.237.10 
192.168.245.10 
192.168.36.2 

bash-3.00$ cat test
1 S8300_LSP_Wich LSP y n 22:00 9/19/2011 6 
192.168.249.10 
No V6 Entry 
2 S8500_ESS_BldgE ESS S y n 22:00 9/19/2011 1 
192.168.237.10 
No V6 Entry 
3 Salina_LSP LSP y n 22:00 9/19/2011 60 
192.168.245.10 
No V6 Entry 
4 bcbshutchlsp LSP y n 22:00 9/19/2011 150
192.168.36.2 
No V6 Entry

---------- Post updated at 07:29 AM ---------- Previous update was at 07:28 AM ----------

Code:
 
nawk ' /^[0-9]+\./ ' test

# 6  
Old 09-21-2011
Through Sed..
Code:
sed '/^[0-9][0-9][^ ]*/!d' inputfile > outfile

# 7  
Old 09-21-2011
try this .
Code:
grep -o "[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*" yourfile


Last edited by Franklin52; 09-21-2011 at 08:37 AM.. Reason: Corrected code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extracting data blocks from file

Hi all, I want to extract blocks of data from a file depending on the contents of that block. The input file(table) has several blocks each starting with 'gene' in the first column. I want to extract only those blocks which do not have the expression '_T02' in the second column. Input file ... (3 Replies)
Discussion started by: newbie83
3 Replies

2. UNIX for Dummies Questions & Answers

Extracting data from file

I am trying to compare the data in lines 3 & 5 to see if they match up to the '-S570' (see first code set, all proprietary information has been removed from code set) spawn telnet Trying ... Connected to CA-LOS1234-ASE-S570.cl . Escape character is '^]'. CA-LOS1234-ASE-S570 Username: ... (1 Reply)
Discussion started by: slipshft
1 Replies

3. Shell Programming and Scripting

Need help in extracting data from xml file

Hello, This is my first post in here, so excuse me if I sound too noob here! I need to extract the path "/apps/mp/installedApps/V61/HRO/hrms_01698_A_qa.ear" from the below xml extract. The path will always appear with the key "binariesURL" <deployedObject... (6 Replies)
Discussion started by: abhishek2386
6 Replies

4. UNIX for Dummies Questions & Answers

Efficient way of extracting data from file

I am having a file, around 500 lines. which contains one letter words, two letters words,...and so on(up to 15 letter words and words are not seprated by line). I need to compare all 1 letter words with 3,4,5 and 6 letters word, all 2 letters words with 2,3,4 and 5 letters words and all 3 letters... (3 Replies)
Discussion started by: akhay_ms
3 Replies

5. 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

6. UNIX for Dummies Questions & Answers

Extracting data from an xml file

Hello, Please can someone assist. I have the following xml file: <?xml version="1.0" encoding="utf-8" ?> - <PUTTRIGGER xmlns:xsd="http://www.test.org/2001/XMLSchema" xmlns:xsi="http://www.test.org/2001/XMLSchema-instance" APPLICATIONNUMBER="0501160" ACCOUNTNAME="Mrs S Test"... (15 Replies)
Discussion started by: Dolph
15 Replies

7. Shell Programming and Scripting

extracting data from a .csv file

I have a .csv file equipment,bandtype abc,aws def,mmds ghi,umts jkl,mmds I can get the equipment from `hostname`. In my script i want to check what is the hostname. then see if it exists in the.csv file. if it does then i want to store the second parameter(bandtype) for the corresponding... (3 Replies)
Discussion started by: lassimanji
3 Replies

8. UNIX for Dummies Questions & Answers

Extracting Data from a File

Hi I need to calculate the number of occurrences of a item in a number of files using Perl. The item appears continually throughout the files but in each case I only want to calculate it in certain blocks of the file. Example - Calculalte the number of occurrences of a 'pass' in a block of... (0 Replies)
Discussion started by: oop
0 Replies

9. Shell Programming and Scripting

Extracting Data from xml file

Hi ppl out there... Can anyone help me with the shell script to extract data from an xml file. My xml file looks like : - <servlet> <servlet-name>FrontServlet</servlet-name> <display-name>FrontServlet</display-name> ... (3 Replies)
Discussion started by: nishana
3 Replies

10. UNIX for Advanced & Expert Users

Extracting data from an AFP file

Hello Anybody any idea how to extract data from an AFP file using UNIX commands? I could make the AFP to PDF or if there is any other to change it to to make the extraction simplar. I'm open to ideas. Cheers (4 Replies)
Discussion started by: Dolph
4 Replies
Login or Register to Ask a Question