Need Shell Script to delete lines in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need Shell Script to delete lines in a file
# 1  
Old 04-22-2010
Need Shell Script to delete lines in a file

Hi All,

I have a file with 3 columns (Bank Name, Account Number and Amount). My requirement, I need to delete lines using Unix Shell script:

1. Which are having Alphanumeric characters in Account Number (eg. Line3).
2. Which are having 0.00 in amount. (eg. Line4)
3. And also I need to delete the text "End Of File".


Sample Data:-
--------------
Bank1,123,100.00
Bank2,456,200.00
Bank3,A789,300.00
Bank4,1011,0.00
End of File
# 2  
Old 04-22-2010
Code:
awk -F, '{f=($NF!="0.00" && $2 !~ /[a-zA-Z]/ && $0!~ /End of File/)?1:0}f' file

# 3  
Old 04-22-2010
Use the following code
Code:
while read line
do
        sed '/.*,[A-Za-z]/d' <<< $line | sed '/^End of File/d'  | sed '/.*,0\.00/d'
done < input > output

Now the output file will contain only the following lines
Code:
Bank1,123,100.00
Bank2,456,200.00

# 4  
Old 04-22-2010
MySQL

Code:
# cat erasefile
Bank1,123,100.00
Bank2,456,200.00
Bank3,A789,300.00
Bank4,1011,0.00
End of File

Code:
# sed -e '/.*[A-Z][0-9].*/d
/,0.00*$/d
/End of File/d' erasefile
Bank1,123,100.00
Bank2,456,200.00

# 5  
Old 04-29-2010
As a matter of form I'll post a perl variant:
Code:
#!/usr/bin/perl
 
my $input='bankdata' ;
 
open(INPUT, "$input") or die "Error opening file: $!\n" ;
   while (<INPUT>) {
   chomp $_;
   @arrr = split(/,/);
    if ($arrr[0] !~ /^End of File/ ) {
      if ($arrr[1] !~ /[A-Z]/) {
 	if ($arrr[2] !~ /^0.00/) {
 	  print ("$_\n");
    }
   }
  }

 else {
 next ;
 }
}
close(INPUT);

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to merge and delete lines

POLY_STATS { EqName 103_tri Id 123 act_polyCount 1 act_polyValue 0 } POLY_STATS { EqName 103_tri Id 123 pass_polyCount 2 pass_polyValue 0 } POLY_STATS { EqName 103 Id 123 mes_polyCount 2 mes_polyValue 0 (5 Replies)
Discussion started by: Jag02
5 Replies

2. Shell Programming and Scripting

Delete all CONSECUTIVE text lines from file shell scripting

Hi I have a text file like below. THe content of the text will vary. Entire text file have four consecutive lines followed with blank line. I want to delete the occurrence of the two consicutive lines in the text file. I don't have pattern to match and delete. Just i need to delete all... (5 Replies)
Discussion started by: RJSKR28
5 Replies

3. Shell Programming and Scripting

How to delete the lines from file using script?

Hi Iam having file like below 10.238.52.65 pun-ras-bng-mhs-01 server 10.238.52.65 pun-ras-bng-mhs-01 10.10.10.10 10.238.52.65 pun-ras-bng-mhs-01 10.10.20.10 10.238.54.1 enk-ras-bng-cse-01 server 10.238.54.1 enk-ras-bng-cse-01 10.10.30.10 10.238.54.1 enk-ras-bng-cse-01 10.10.10.10 ... (5 Replies)
Discussion started by: surender reddy
5 Replies

4. Shell Programming and Scripting

script to delete lines from a txt file if pattern matches

File 6 dbnawldb010-b office Memphis_Corp_SQL_Diff Memphis-Corp-SQL-Inc-Application-Backup 03/09/11 03:24:04 42 luigi-b IPNRemitDB Memphis_Corp_SQL_Diff Memphis-Corp-SQL-Inc-Application-Backup 03/10/11 00:41:36 6 ebs-sqldev1-b IPNTracking Memphis_Corp_SQL_Diff... (4 Replies)
Discussion started by: ajiwww
4 Replies

5. Shell Programming and Scripting

looking for a script that will delete lines in a text file

it will grep for a line and then delete these line. how do i begin to write this script if theres no available one? (3 Replies)
Discussion started by: garfish
3 Replies

6. Shell Programming and Scripting

HP Unix Script to Delete the lines in a file

Hi Experts, I have a file format as mentioned below. I would like to have unix script (HP Unix) which can: 1. Remove first 6 and last 3 lines. 2. Delete the lines where 3rd column having Alpha Numeric Number 3. Delete the lines where 4th column having 0.00 4. Calculate the sum of all the... (16 Replies)
Discussion started by: phani333
16 Replies

7. Shell Programming and Scripting

Delete lines from file using Unix Script

Hi Experts, I have a file in the below given format. First two lines are header and Trailer. Rest all are transaction Lines. I have to delete all other lines except first line (Header) and lines which contains 5000 in 1st column and 0 in 5th column. Can anyone please kindly provide me with... (6 Replies)
Discussion started by: phani333
6 Replies

8. Shell Programming and Scripting

Delete lines at several places in a file with script

Hi, I am a newbie to shell scripting, and I have a file which quite large which I would like to delete lines at certain places. I want to search for a keyword which is recurring in the file. When matched I would like to delete the line. And when the file was so huge I thought I ought to learn... (3 Replies)
Discussion started by: mr_andrew
3 Replies

9. Shell Programming and Scripting

Need Help: Delete a file by Shell Script

Need some help here. We FTP out files to another server hourly. But before we can FTP to the other server. That server should send our server a "confirmation file" to tell us that they're ready to receive data. If they don't send the confirmation file, the files on our server should just stay... (5 Replies)
Discussion started by: r3edi
5 Replies

10. Shell Programming and Scripting

How to Delete all lines in a file from a script

I am trying to delete all the lines out a file from a unix script. Please help Platform is Sun (3 Replies)
Discussion started by: alnita
3 Replies
Login or Register to Ask a Question

Featured Tech Videos