filtering the rows in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting filtering the rows in a file
# 1  
Old 02-15-2011
filtering the rows in a file

hi all,

please help on this isssue, i have a file which contains something like this

Quote:
########
#server1
########
/var/opt/quest/vas/vasd/.vasd.pid
var/opt/quest/vgp/vasgpd/.vasgpd.pid

#########
#server2
########
grep -i vas
/bin/bash -c ps -ef |grep -i vas

########
#server3
########
/var/opt/quest/vas/vasd/.vasd.pid
var/opt/quest/vgp/vasgpd/.vasgpd.pid
and i want to seprate the servers which has vasd.pid ,i need only server names.

i want output something like this which vasd.pid .

server1
server3
server4
# 2  
Old 02-15-2011
Code:
awk 'BEGIN{RS="";FS="\n"} /vasd.pid/ {print substr($2,2)}' infile


Last edited by rdcwayx; 02-15-2011 at 10:34 PM..
# 3  
Old 02-15-2011
Code:
awk '/^#[^#]/ { S=substr($0,2) }
   /vasd.pid/ && S { print S; S="" }' infile

# 4  
Old 02-15-2011
Code:
echo "########
#server1
########
/var/opt/quest/vas/vasd/.vasd.pid
var/opt/quest/vgp/vasgpd/.vasgpd.pid

#########
#server2
########
grep -i vas
/bin/bash -c ps -ef |grep -i vas

########
#server3
########
/var/opt/quest/vas/vasd/.vasd.pid
var/opt/quest/vgp/vasgpd/.vasgpd.pid" | awk '/server/ {X=substr($1,2,7)} /vasd.pid/ {print X}'
server1
server3

# 5  
Old 02-16-2011
Chubler_XL

getting error;
HTML Code:
awk: syntax error near line 2
awk: bailing out near line 2
 
rdcwayx

thanks it works fine
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Moving or copying first rows and last rows into another file

Hi I would like to move the first 1000 rows of my file into an output file and then move the last 1000 rows into another output file. Any help would be great Thanks (6 Replies)
Discussion started by: kylle345
6 Replies

2. Shell Programming and Scripting

Filtering out rows

# powermt display dev=all .... snipped ... Pseudo name=hdiskpower8 Symmetrix ID=000192602584 Logical device ID=059F state=alive; policy=SymmOpt; priority=0; queued-IOs=0 ============================================================================== ---------------- Host --------------- ... (7 Replies)
Discussion started by: Daniel Gate
7 Replies

3. Shell Programming and Scripting

Filtering first file columns based on second file column

Hi friends, I have one file like below. (.csv type) SNo,data1,data2 1,1,2 2,2,3 3,3,2 and another file like below. Exclude data1 where Exclude should be treated as column name in file2. I want the output shown below. SNo,data2 1,2 2,3 3,2 Where my data1 column got removed from... (2 Replies)
Discussion started by: ks_reddy
2 Replies

4. UNIX for Dummies Questions & Answers

merging rows into new file based on rows and first column

I have 2 files, file01= 7 columns, row unknown (but few) file02= 7 columns, row unknown (but many) now I want to create an output with the first field that is shared in both of them and then subtract the results from the rest of the fields and print there e.g. file 01 James|0|50|25|10|50|30... (1 Reply)
Discussion started by: A-V
1 Replies

5. UNIX for Dummies Questions & Answers

Filtering records from 1 file based on some manipulation doen on second file

Hi, I am looking for an awk script which should help me to meet the following requirement: File1 has records in following format INF: FAILEd RECORD AB1234 INF: FAILEd RECORD PQ1145 INF: FAILEd RECORD AB3215 INF: FAILEd RECORD AB6114 ............................ (2 Replies)
Discussion started by: mintu41
2 Replies

6. Shell Programming and Scripting

filtering the log file

Hi i have a log file like example below. I need only one field from below log all other need to be truncated from the log file. 2011-06-13 15:10:53,498 INFO ext.SP->CAL (log point 5) can any body help on this please. Thanks (4 Replies)
Discussion started by: mostwantedkisss
4 Replies

7. UNIX for Dummies Questions & Answers

Filtering a file

I have a list of directories looking something like; /usr/local/1/in /usr/local/1/out /usr/local/1/archive /usr/local/2/in /usr/local/2/out /usr/local/2/archive /usr/local/3/in /usr/local/3/out /usr/local/3/archive Is there a way I can filter the out and archive directories so I... (5 Replies)
Discussion started by: JayC89
5 Replies

8. Shell Programming and Scripting

Filtering rows for first two instances of a value

Kindly help me with this problem: My data looks like this: SNPfile.txt CHR_A BP_A SNP_A CHR_B BP_B SNP_B R2 p-SNP_A p-SNP_B 4 172575323 rs17056855 4 172601079 rs11945883 0.119414 0.049972656 0.031050345 4 172575323 rs17056855 4 ... (2 Replies)
Discussion started by: genehunter
2 Replies

9. Shell Programming and Scripting

delete rows in a file based on the rows of another file

I need to delete rows based on the number of lines in a different file, I have a piece of code with me working but when I merge with my C application, it doesnt work. sed '1,'\"`wc -l < /tmp/fileyyyy`\"'d' /tmp/fileA > /tmp/filexxxx Can anyone give me an alternate solution for the above (2 Replies)
Discussion started by: Muthuraj K
2 Replies

10. Shell Programming and Scripting

Command filtering ONLY rows NOT beginning with '*'

I need a command which filters rows ONLY NOT beginning with '*' So far I have following NOT sufficient command, because it does not include ALL possible literals except of '*' grep ^ INPUT_FILE >>OUTPUT_FILE Is it possible to write something like grep NOT ^ INPUT_FILE... (3 Replies)
Discussion started by: ABE2202
3 Replies
Login or Register to Ask a Question