how to filter files with given format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to filter files with given format
# 1  
Old 08-21-2012
how to filter files with given format

Hi, all, I have files like:
Code:
nameserver 216.66.22.2                           ; tserv1.ash1.ipv6.he.net. tserv13.ash1.ipv6.he.net.
nameserver 216.66.38.58                          ; tserv1.tor1.ipv6.he.net. tserv21.tor1.ipv6.he.net.
nameserver 216.218.221.6                         ; tserv1.hkg1.ipv6.he.net. tserv20.hkg1.ipv6.he.net.
nameserver 216.218.226.238                       ; tserv1.sea1.ipv6.he.net. tserv14.sea1.ipv6.he.net.
nameserver 2001:470:0:470::470                   ; ns1.fmt.he.net. - Filtered
nameserver 2001:470:0:471::471                   ; ns2.fmt.he.net. - Filtered
nameserver 2001:470:0:472::472                   ; ns1.sjc.he.net. - Filtered
nameserver 2001:470:0:473::473                   ; ns1.fmt2.he.net. - Filtered

;
; Cogent
; These servers may not be reachable as Cogent does not have peering with some ISPs and refuses to buy transit.
;
nameserver 2001:978:1:1::d                       ; eu-res1.dns.cogentco.com.
nameserver 2001:978:1:2::d                       ; eu-res2.dns.cogentco.com.
nameserver 2001:978:1:20::1a                     ; res1-fra03-v6.sys.cogentco.com.
nameserver 2001:978:1:22::1a                     ; res1-mad05-v6.sys.cogentco.com.
nameserver 2001:550:1:1::d                       ; na-res1.dns.cogentco.com.
nameserver 2001:550:1:2::d                       ; na-res2.dns.cogentco.com.
nameserver 2001:550:1:2:203:baff:fe2c:c022       ; <unknown>
nameserver 2001:550:1:20::1a                     ; res1-herndon-v6.sys.cogentco.com.
nameserver 2001:550:1:21::2a                     ; res2-herndon-v6.sys.cogentco.com.
nameserver 2001:550:1:22::1a                     ; res1-nyc-v6.sys.cogentco.com.
nameserver 2001:550:1:23::2a                     ; res2-nyc-v6.sys.cogentco.com.
nameserver 2001:550:1:24::1a                     ; res1-chi-v6.sys.cogentco.com.
nameserver 2001:550:1:25::2a                     ; res2-chi-v6.sys.cogentco.com.
nameserver 2001:550:1:26::1a                     ; res1-la-v6.sys.cogentco.com.
nameserver 2001:550:1:27::2a                     ; res2-la-v6.sys.cogentco.com.
nameserver 2001:550:1:27:203:baff:fe2c:c022      ; <unknown>

I want to extract the ipv4 addresses(the format is x.y.z.k) and put them into a new list

how to achieve this? thanks
# 2  
Old 08-21-2012
Code:
grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' file 

216.66.22.2
216.66.38.58
216.218.221.6
216.218.226.238

This User Gave Thanks to in2nix4life For This Post:
# 3  
Old 08-21-2012
Can you show some examples

Are you just trying to get the four 216. --- addresses in those first four lines?
# 4  
Old 08-22-2012
Code:
awk '{n=split($2,a,".");if(n==4)print $2}' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Can we filter the below log data into CSV format?

HI , I m looking for help here!!! Can we filter the below log data into CSV format ? timestamp INFO <text > - Some text Drive .. Need a format of separate field such as 1 2 3 4 ... (2 Replies)
Discussion started by: MohSalNiz
2 Replies

2. Shell Programming and Scripting

Filter using awk in CSV files

Hello Gentlemen, Finding difficulties to play with my Input files:confused: . Your guidance will certainly help as always. After converting to csv file from XLSM file, I am getting some extra ""(double quote) characters which I want to terminate inside shell script and process it further. ... (6 Replies)
Discussion started by: pradyumnajpn10
6 Replies

3. UNIX for Dummies Questions & Answers

Filter and merge 2 files problem

Hi, I'm trying to combine two files which have 1 column in common and filter out rows I don't need. File 1: ID Start End Matched Coverage 1 1 254 1515 5.96 2 1 135 402 2.98 File 2 (has 2 rows per entry): >1... (4 Replies)
Discussion started by: Yarinka
4 Replies

4. Shell Programming and Scripting

<< Filter and Format the ouput >>

Hi All, I have a output like below $ cat aa.lst Value of output parameters --------------------------------------- Parameter Name : SNAPSHOTTIMESTAMP Parameter Value : 2014-01-07-15.21.50.022423 Parameter Name : DATABASESIZE Parameter Value : 96178176 ... (2 Replies)
Discussion started by: kamauv234
2 Replies

5. UNIX for Dummies Questions & Answers

Filter lines common in two files

Thanks everyone. I got that problem solved. I require one more help here. (Yes, UNIX definitely seems to be fun and useful, and I WILL eventually learn it for myself. But I am now on a different project and don't really have time to go through all the basics. So, I will really appreciate some... (6 Replies)
Discussion started by: latsyrc
6 Replies

6. Shell Programming and Scripting

Copying the files after filter

Hi Guys, i want copy the all files another direcotry after filtering the command. and tried as like below...it's not working. ls -ltr|awk '{print $9}'|grep "images\|\.htm"|cp *.* /home/oracle Thanks (13 Replies)
Discussion started by: bmk
13 Replies

7. Shell Programming and Scripting

Need script for transferring bulk files from one format to text format

"Help Me" Need script for transferring bulk files from one format to text format in a unix server. Please suggest (2 Replies)
Discussion started by: Kranthi Kumar
2 Replies

8. UNIX for Dummies Questions & Answers

Search and filter between two files

Hello, I have two files in this form that consist of three columns, a name (L*contig*), the length (length=**) and the sequence LT_file.txt LTcontig1 length=13 acccatgctttta LTcontig5 length=8 ggattacc LTcontig8 length=20 ccattgaccgtacctgatcg LTcontig23 length=5 accta and... (5 Replies)
Discussion started by: FelipeAd
5 Replies

9. Shell Programming and Scripting

Filter files and print

Hi, I need to filter and store the files ends with log extension in the array and need to write the file names in the array to a file. I need to use array to derive this solution. Please help me out. Thanks (2 Replies)
Discussion started by: Sekar1
2 Replies

10. Shell Programming and Scripting

Filter only gz files from list of subdirectories

Hi, I have a very big directory structure that consists of many sub-directories inside.There are around 50 ".gz" files under this dir structure. I want to copy all the gz files alone to a seperate location. Plz help me. (2 Replies)
Discussion started by: villain41
2 Replies
Login or Register to Ask a Question