how to write a function to get data under spesific lines ? using bash


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to write a function to get data under spesific lines ? using bash
# 1  
Old 11-02-2011
Question how to write a function to get data under spesific lines ? using bash

I have a text file called ( bvhz ) contains data :

Subscriber
Data ID = 2
Customer = 99
Data ID = 4
Customer = cf99
Data ID = 5
Customer = c99
Data ID = 11
Customer = 9n9

Subscriber
Data ID = 1
Customer = 9ds9
Data ID = 2
Customer = 9sad9
Data ID = 3
Customer = f99
Data ID = 4
Customer = 9sg9
Data ID = 5
Customer = 9sg
Data ID = 8
Customer = 99

And so on for # of subscribers
I want to write a function to get me the customer number under Data ID = 4
Note: number of lines containing data id variable and not in same place 4 every subscriber

Output file >
Cf994
9sg9
Null ------------ if its not found ( data id = 4 under each subscriber )
.....

Please help I think its impossible
# 2  
Old 11-02-2011
Is Customer always immediately after Data ID?

If so you could do:
Code:
grep -A1 "Data ID = 4" infile | awk '/Customer/ {print $2}'

(GNU grep)

EDIT: duplicate thread
This User Gave Thanks to CarloM For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

MAN and read & write function

How to use MAN to find information about read() and write() function ? The command "man read" show some rubbish, for example "man open" show great information about function I need. (2 Replies)
Discussion started by: bbqtoss
2 Replies

2. Shell Programming and Scripting

Remove lines if some data is the same: Centos5 / bash

Ok what i have is 8 separate files based on how many IP's are associated with the domain. I want to limit duplication of ip's within the individual files (ie. i don't care if the same ip is in 1 IP file and 4 IP file). Can someone help me with how to go through the files and remove lines that have... (3 Replies)
Discussion started by: oly_r
3 Replies

3. Shell Programming and Scripting

how to write a function or awk fn ? , please help !!

************* fixed *************** Begin equipmentId : d9 processor : fox number : bhhhhhh Variable # 1: Id : 100 Type : 9 nType : s gType : 5f mType : 4 LField : England DataField : london Length : 4 End (20 Replies)
Discussion started by: teefa
20 Replies

4. Homework & Coursework Questions

Shell script calling Perl function, sort and find data, write to new files

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I must write a shell script that calls two external Perl functions--one of which sorts the data in a file, and... (6 Replies)
Discussion started by: kowit010
6 Replies

5. UNIX for Dummies Questions & Answers

how to write a function to get data under specific lines ?

I have a text file called (msgz ) contains data : Subscriber Data ID = 2 Customer = 99 Data ID = 4 Customer = cf99 Data ID = 5 Customer = c99 Data ID = 11 Customer = 9n9 Subscriber Data ID = 1 Customer = 9ds9 Data ID = 2 Customer = 9sad9 Data ID = 3 Customer = f99... (3 Replies)
Discussion started by: teefa
3 Replies

6. Shell Programming and Scripting

Extracting specific lines of data from a file and related lines of data based on a grep value range?

Hi, I have one file, say file 1, that has data like below where 19900107 is the date, 19900107 12 144 129 0.7380047 19900108 12 168 129 0.3149017 19900109 12 192 129 3.2766666E-02 ... (3 Replies)
Discussion started by: Wynner
3 Replies

7. Homework & Coursework Questions

Write a function named isPrime

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Write a function named isPrime which accepts one integer parameter, say x. Have the function return TRUE if x... (4 Replies)
Discussion started by: KyleBucket
4 Replies

8. Shell Programming and Scripting

[BASH] Using a function to write data to a file

Hello, I've created a shell script, which accepts information using an input from the console. Part of the script will write a file containing this information. My code looks like (for the write) function make_file { cat <<- _EOF_ The contents of my file are here _EOF_ } ... (12 Replies)
Discussion started by: cpickering
12 Replies

9. Shell Programming and Scripting

how to write divided function

hi iam facing problem for divided (%) arthemtic function in for condition. tell me reply and all the arthemtic function in one scripting . (2 Replies)
Discussion started by: naveeng.81
2 Replies

10. Shell Programming and Scripting

How To Write Sed Function

hi iam facing problem regarding sed function. give me reply with example of sed function. and what to meanings of $# and @ in scripting please as reply as soon as possible (1 Reply)
Discussion started by: naveeng.81
1 Replies
Login or Register to Ask a Question