Filter data from text file


 
Thread Tools Search this Thread
Special Forums Windows & DOS: Issues & Discussions Filter data from text file
# 8  
Old 04-14-2008
Code:
awk '/^----*Table/{table=$0}
/^IP=/{ print table }' file

Do you really have a variable number of dashes before the "Table"?
# 9  
Old 04-14-2008
Code:
awk '$0 ~ v { printf "%s\n%s\n", x, $0 }
/^--/ { x = "" } { x = x ? x RS $0 : $0 }
' v="^IP=172.18.0.1$" file

Use nawk or /usr/xpg4/bin/awk on Solaris.

Perhaps I misread the question, if you need only the table names,
you should use the code era posted.
# 10  
Old 04-15-2008
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.
# 11  
Old 04-15-2008
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

# 12  
Old 04-15-2008
/usr/xpg4/bin/awk: syntax error Context is:
>>> END { if (f) print x } $0 ~ v && f++/---- <<<
# 13  
Old 04-15-2008
Quote:
Originally Posted by Hone1975
/usr/xpg4/bin/awk: syntax error Context is:
>>> END { if (f) print x } $0 ~ v && f++/---- <<<
Copy/paste my code,
there's a newline after f++ ...

(why this thread is in Windows & DOS: Issues & Discussions?)
# 14  
Old 04-15-2008
Quote:
Originally Posted by radoulov
Copy/paste my code,
there's a newline after f++ ...

(why this thread is in Windows & DOS: Issues & Discussions?)
Why this thread: This case was very near of my needs and I am very new forum user and I didn't remenber to check is my case in the right place.

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).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Filter records in a huge text file from a filter text file

Hi Folks, I have a text file with lots of rows with duplicates in the first column, i want to filter out records based on filter columns in a different filter text file. bash scripting is what i need. Data.txt Name OrderID Quantity Sam 123 300 Jay 342 498 Kev 78 2500 Sam 420 50 Vic 10... (3 Replies)
Discussion started by: tech_frk
3 Replies

2. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

3. UNIX for Dummies Questions & Answers

Solaris - Filter columns in text file and adding new column

Hello, I am very now to this, hope you can help, I am looking into editing a file in Solaris, with dinamic collums (lenght varies) and I need 2 things to be made, the fist is to filter the first column and third column from the file bellow file.txt, and create a new file with the 2 filtered... (8 Replies)
Discussion started by: jpbastos
8 Replies

4. Shell Programming and Scripting

How to filter out data file...?

Hi... I would like to filter out my data file....in two different way 1st way is like this, I will take one example..here... The script should ask like this. Enter min value in first column Enter max value in first column Enter min value in second column Enter max value in... (5 Replies)
Discussion started by: nex_asp
5 Replies

5. Shell Programming and Scripting

Filter a .kml file (xml) with data set from text file

I have a .kml file. So I want filter the .kml to get only the tags that have this numeric codes that they are in a text file 11951 11952 74014 11964 11965 11969 11970 11971 11972 60149 74018 74023 86378 11976 11980 11983 11984 11987 (5 Replies)
Discussion started by: pcoj33
5 Replies

6. UNIX for Dummies Questions & Answers

Need to filter data from a file

Hi, I have a file with hundreds of records. There are four fields on each line, separated by semicolons. Name Height (meters) Country Continent (Africa,Asia,Europe,North America,Oceania,South America,The Poles) I need to Write the command to find display how many mountains appear... (1 Reply)
Discussion started by: erora
1 Replies

7. Shell Programming and Scripting

How to filter required data from file using bash script?

Hi All , I have one file like below , Owner name = abu2-kxy-m29.hegen.app Item_id = AX1981, special_id = *NULL*, version = 1 Created = 09/01/2010 12:56:56 (1283389016) Enddate = 03/31/2011 00:00:00 (1301554800) From the above file I need to get the output in the below format ,i need... (3 Replies)
Discussion started by: gnanasekar_beem
3 Replies

8. UNIX for Advanced & Expert Users

filter last 24 hour data and put in new file

i have file server 1 (filesvr01acess.log) and disc server 1 (discsvr01acess.log) in unix box(say ip adress of the box 10.39.66.81) Similiarly i have file server 2 (filesvr01acess.log) and disc server 2(discsvr01acess.log) in another unix box(say ip adress of the box 10.39.66.82). Now my... (1 Reply)
Discussion started by: nripa1
1 Replies

9. Shell Programming and Scripting

Shell script to read lines in a text file and filter user data

hi all, I have this file with some user data. example: $cat myfile.txt FName|LName|Gender|Company|Branch|Bday|Salary|Age aaaa|bbbb|male|cccc|dddd|19900814|15000|20| eeee|asdg|male|gggg|ksgu|19911216||| aara|bdbm|male|kkkk|acke|19931018||23| asad|kfjg|male|kkkc|gkgg|19921213|14000|24|... (4 Replies)
Discussion started by: srimal
4 Replies

10. UNIX for Dummies Questions & Answers

Using input file to filter data from another file

I have a data file: abc Text Text Text Unique Text 123 Text word Line Unique Text fgh Text data Line Unique Text 789 Text Text Line Unique Text 543 Text Text Data Unique Text and a filter file 123 789 I want to extract out from the data file the two records that contain the keys... (1 Reply)
Discussion started by: tumblez
1 Replies
Login or Register to Ask a Question