Read file based on condition


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read file based on condition
# 1  
Old 02-01-2007
Read file based on condition

Hi Friends,

Can any one help with this:
I have a huge file with the format as
A SAM 4637
B DEPT1 4758 MILAN
A SMITH 46585
B DEPT2 5385 HARRYIS
B SAMUL 63547 GEORGE
B DANIEL 899 BOISE
A FRES 736 74638


I have to read this file and write only the records that starts with "B" only

output should be:
B DEPT1 4758 MILAN
B DEPT2 5385 HARRYIS
B SAMUL 63547 GEORGE
B DANIEL 899 BOISE



Thanks in advance

S Smilie
# 2  
Old 02-01-2007
grep "^B" < data
# 3  
Old 02-01-2007
thanks a lot
# 4  
Old 02-01-2007
It will work even with out ^
# 5  
Old 02-01-2007
Quote:
Originally Posted by gopinathsekar
It will work even with out ^
No, it won't work, we need to find lines containing a "B" at the start, so we need to mention it, a "^B" tells grep to look for lines having B as their first character, hope you got the concept.
# 6  
Old 02-01-2007
Quote:
Originally Posted by tayyabq8
No, it won't work, we need to find lines containing a "B" at the start, so we need to mention it, a "^B" tells grep to look for lines having B as their first character, hope you got the concept.

I got it.....Thanks tayyabq8.......... Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Join fields in a same file based on condition

I have an input file like this... All iI want to do is If the lines are identical except for the last field i want to merge them into single line input_file I feel something is nothing I feel something is everything apple mango banana apple mango grapes I want to get output like this:... (3 Replies)
Discussion started by: raj_k
3 Replies

2. Shell Programming and Scripting

Delete lines from file based on condition

I want to keep last 2 days data from a file and want to delete others data from the file. Please help me. Sample Input # cat messages-2 Apr 15 11:25:03 test1 kernel: imklog 4.6.2, log source = /proc/kmsg started. Apr 15 11:25:03 test1 rsyslogd: (re)start Apr 16 19:42:03 test1 kernel:... (2 Replies)
Discussion started by: makauser
2 Replies

3. Shell Programming and Scripting

Adding data from a file based on some condition

I collect data in a file in below format(Month Day Year Size) in RedHat Linux. Now i want to calculate the data size date wise. As i code shell script after long time, i forgot the features and syntax. Can anyone help me regard this please. Feb 8 2014 15 Feb 10 2014 32 Feb 10 2014 32 Feb 12... (2 Replies)
Discussion started by: makauser
2 Replies

4. Shell Programming and Scripting

Read 2 files alternatively based on condition.

Experts, What would be the code in ksh/perl to read 2 files alternatively, based on the following condition. while reading file 1 we check if a blank line is encountered, if yes, then we read file 2 unless a blank line is encountered in file 2 if we have a blank line in file 2 we come back... (3 Replies)
Discussion started by: suraj.sheikh
3 Replies

5. Shell Programming and Scripting

How can I change file value based on condition

Hi, Gurus, I got a problem to resolve following issue: I have one file file1as following: start_dt=2010-01-01 12:00:02 start_dt=2011-01-01 09:00:02 start_dt=2009-01-01 11:00:02I have another file file2 as following: title1, 2010-01-03 10:00:02 title2, 2011-01-04 11:00:02 title3,... (5 Replies)
Discussion started by: ken002
5 Replies

6. Shell Programming and Scripting

Move input file based on condition

Hello, I have File1 in a directory A, a File2 in a directory B. If the File2 is not empty Then I have to move File1 from directory A to a directory archive Else no action. Is it possible to do this from one command line? Thank you in advance for your answers. Madi (2 Replies)
Discussion started by: AngelMady
2 Replies

7. Shell Programming and Scripting

Update a field in a file based on condition

Hi i am new to scripting. i have a file file.dat with content as : CONTENT_STORAGE PERCENTAGE FLAG: /storage_01 64% 0 /storage_02 17% 1 I need to update the value of FLAG for a particular CONTENT_STORAGE value I have written the following code #!/bin/sh threshold=20... (1 Reply)
Discussion started by: kichu
1 Replies

8. Shell Programming and Scripting

Spliting file based on condition

Hi, I have a comma separated file with millions of records in it. I have a requirement to split the file based on the value in a one of the columns. Suppose i have a text file with columns like C1, C2,C3,C4 Column C4 can hold the values either 01 or 02 03 or 04. I nned to extract... (2 Replies)
Discussion started by: Raamc
2 Replies

9. Shell Programming and Scripting

Moving file to directory based on condition.

Can any one help me to correct following script. I have 2 directories DropZone and ProcessZone. File pattern is *VEHDESCSUM*. Finding the 'no of files' in DropZone directory using ls *VEHDESCSUM* |wc -l If DropZone has more than one file or 0 files then exit 1 If DropZone has one file then... (2 Replies)
Discussion started by: ramanagh
2 Replies

10. Shell Programming and Scripting

Splitting a file based on some condition and naming them

I have a file given below. I want to split the file where ever I came across ***(instead you can put ### symbols in the file) . Also I need to name the file by extracting the report name from the first line which is in bold(eg:RPT507A) concatinated with DD(day on which the file runs). Can someone... (1 Reply)
Discussion started by: srivsn
1 Replies
Login or Register to Ask a Question