![]() |
|
|
|
|
|||||||
| Windows & DOS: Issues & Discussions Questions involving Unix to Windows (Desktop or Server) go here. Any Windows/DOS questions should go here as well. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Extracting data from text file based on configuration set in config file | suparnbector | Shell Programming and Scripting | 3 | 08-09-2007 11:25 PM |
| Exporting text file data to csv | l_jayakumar | Shell Programming and Scripting | 3 | 09-18-2005 08:27 PM |
| filter data | deep.singh | UNIX for Dummies Questions & Answers | 3 | 08-14-2005 08:24 PM |
| How to extract data from a text file | negixx | Shell Programming and Scripting | 1 | 07-19-2005 06:30 PM |
| getting data out from a text file | skotapal | Shell Programming and Scripting | 7 | 09-14-2002 08:10 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
Filter data from text file
Hi All
We have got a text file, which has data dumped from 60 tables. From these 60 tables of data we need data from 4 tables only. I tried assigning line numbers to filter out data, but it is not working as intended. below is the sample file ----Table1----- 3,dfs,43,df 4,sd,5,edd 56,df,6,fgdg ---Table2--- 54,fdgfg,fgdfg 65,dgdfg,yuytr 76,tyuuu,ytur ---Table3---- 98,rere,78 87,gdg,87 45,hgff,98 ---Table4--- sdfsd,tyut,676 ffsdf,ggfd,879 ghgf,iyuty,877 Say from the file, i need to filter out data for Table2 and Table 3 only ... Can any suggest a solution for this .. Thanks in Advance Sri.... |
| Forum Sponsor | ||
|
|
|
|||
|
Without an example, it's hard to guess. The example you posted so far only has 12345 and asdfghjkl, which of those is supposed to be an IP address?
Maybe it would be easier if you split the single file into multiple files first. Then it's a simple matter of grep -l IP=whatever files |
|
|||
|
Thx for your answer. Here is one example.
----Table1----- 3,dfs,43,df 4,sd,5,edd 56,df,6,fgdg IP=172.18.0.1 ---Table2--- 54,fdgfg,fgdfg 65,dgdfg,yuytr 76,tyuuu,ytur IP=172.18.0.2 ---Table3---- 98,rere,78 87,gdg,87 45,hgff,98 IP=172.18.0.1 ---Table4--- sdfsd,tyut,676 ffsdf,ggfd,879 ghgf,iyuty,877 IP=172.18.0.1 ----Table5----- 3,dfs,43,df 4,sd,5,edd 56,df,6,fgdg IP=172.18.0.2 ---Table6--- 54,fdgfg,fgdfg 65,dgdfg,yuytr 76,tyuuu,ytur IP=172.18.0.5 ---Table7---- 98,rere,78 87,gdg,87 45,hgff,98 IP=172.18.0.10 ---Table8--- sdfsd,tyut,676 ffsdf,ggfd,879 ghgf,iyuty,877 IP=172.18.0.111 In one file there is over 100 000 tables and I want to find out those tables where IP=172.18.0.1 |
|
|||
|
Thank you radoulov and era.
Radoulov solution very near that what I am looking for. This script (radoulov) print out from tables only those rows which are before IP=x.x.x.x After IP=x.x.x.x are couple rows more and I like to print out those too. |
|
|||
|
Quote:
Sorry. What do you mean new line? If I put your code to my Solaris shell window I get error message (If I copy and paste your code). |
|
||||
|
Strange,
it seems that you're running this: Code:
awk 'END { if (f) print x } $0 ~ v && f++ /^--/ { if (f) print x; x = f = 0 }
{ x = x ? x RS $0 : $0 }' v="^IP=172.18.0.1$" file
Code:
awk 'END { if (f) print x } $0 ~ v && f++
/^--/ { if (f) print x; x = f = 0 }
{ x = x ? x RS $0 : $0 }' v="^IP=172.18.0.1$" file
Anyway, try separating the statments explicitly: Code:
awk 'END { if (f) print x } $0 ~ v && f++;
/^--/ { if (f) print x; x = f = 0 }
{ x = x ? x RS $0 : $0 }' v="^IP=172.18.0.1$" file
|
||||
| Google UNIX.COM |
| Tags |
| solaris |
| Thread Tools | |
| Display Modes | |
|
|
|
The 50 most popular UNIX and Linux searches.
Google Search Cloud for The UNIX and Linux Forums
|
| 421 service not available, remote server has closed connection ^m automate ftp autosys awk trim bash eval bash for loop boot: cannot open kernel/sparcv9/unix command copy/move folder in unix couldn't set locale correctly curses.h cut command in unix export command in unix find grep find mtime find null character in a unix file grep multiple lines grep or grep recursive hp-ux ifconfig inaddr_any inappropriate ioctl for device lynx javascript mailx attachment mget mtime ping port remove first character from string in k shell replace space by comma , perl script rsync ftp scp recursive segmentation fault(coredump) sftp script snoop unix stale nfs file handle syn_sent tar exclude tar extract to folder test: argument expected unix unix .profile unix forum unix forums unix internals unix interview questions unix mtime unix simulator unix.com v |