file traversal


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting file traversal
# 1  
Old 10-12-2012
file traversal

Hi,
I have to get some value of the from a flat file and my file format is like this.

ABC
DEF
HIJ=1

XYZ
xyz
HIJ=2

So i need to make sure i get all the value of HIJ under XYZ and not ABC.
# 2  
Old 10-12-2012
Hi
Code:
$ awk -F= 'f && /HIJ/{print $2;f=0}/XYZ/{f=1;}' file
2

Guru.
# 3  
Old 10-12-2012
need more

thanks Guru. I need to get more out of it.
A
a=1
b=2
c=3
d=4

B
a=1
b=2
c=3
d=4

I need all the value of the vars from B and not A and print values in
tabular format(\t). Please explain the command so that i can tweak it.
# 4  
Old 10-12-2012
I wonder at times why people give their requirements in installments!! Please provide the exact requirement at the first instance itself:

Code:
$ awk -F= 'f{x=x?x"\t"$2:$2;}/B/{f=1;}/^$/{f=0}END{print x}' file
1       2       3       4

We set a flag variable 'f' to 1 when the pattern B is encountered. Once f is 1, we accumulate all the values in a variable "x". And the variable is printed at the end.

Guru.
# 5  
Old 10-12-2012
sorry about that...thanks alot for your time
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script (sh file) logic to compare contents of one file with another file and output to file

Shell script logic Hi I have 2 input files like with file 1 content as (file1) "BRGTEST-242" a.txt "BRGTEST-240" a.txt "BRGTEST-219" e.txt File 2 contents as fle(2) "BRGTEST-244" a.txt "BRGTEST-244" b.txt "BRGTEST-231" c.txt "BRGTEST-231" d.txt "BRGTEST-221" e.txt I want to get... (22 Replies)
Discussion started by: pottic
22 Replies

2. Shell Programming and Scripting

Compare 2 text file with 1 column in each file and write mismatch data to 3rd file

Hi, I need to compare 2 text files with around 60000 rows and 1 column. I need to compare these and write the mismatch data to 3rd file. File1 - file2 = file3 wc -l file1.txt 58112 wc -l file2.txt 55260 head -5 file1.txt 101214200123 101214700300 101250030067 101214100500... (10 Replies)
Discussion started by: Divya Nochiyil
10 Replies

3. Shell Programming and Scripting

Match list of strings in File A and compare with File B, C and write to a output file in CSV format

Hi Friends, I'm a great fan of this forum... it has helped me tone my skills in shell scripting. I have a challenge here, which I'm sure you guys would help me in achieving... File A has a list of job ids and I need to compare this with the File B (*.log) and File C (extend *.log) and copy... (6 Replies)
Discussion started by: asnandhakumar
6 Replies

4. Shell Programming and Scripting

AWK File Traversal

Hey, I'm working on a file traversal and extraction function and am having problems. So, my script is finding all files in a directory. Each file has the same format. I need to extract a field from the 4th line of each file..... hence why I am using the substring on NR == 4. So, I am... (11 Replies)
Discussion started by: beefeater267
11 Replies

5. UNIX for Advanced & Expert Users

need help in file traversal via FTS(3)

Hi friends, I was trying to traverse a file using FTS(3) . this is the code below.. but I am getting segmentation error in the line fts_read(...) , anybody have any idea , why it is? Please, help me. Thanks in advance.... (2 Replies)
Discussion started by: jack85
2 Replies

6. Shell Programming and Scripting

Creating breadth traversal binary tree

I almost have the entire script written. however the problem is how would i assign the global variable to terminate the process from the bottom up to ensure the child terminates so the parent can. ex. I am proccess 1 I am proccess 2 etc Here is the code $ cat tree.c ... (3 Replies)
Discussion started by: slurpeyatari
3 Replies

7. UNIX for Dummies Questions & Answers

Command line traversal

What is a key, if on command line I have to trverse left & right word by word, instead of character by character? (7 Replies)
Discussion started by: videsh77
7 Replies
Login or Register to Ask a Question