Help with shell script for regular file

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help with shell script for regular file
# 1  
Old 03-29-2014
Help with shell script for regular file

HI All,

I have a to write a shell script where a file will have I,D,U opertaions for example


My requuirement is ,if any two same records with insert and update operations then update record shud be deleted.similarly if any two same records with insert and delete operations then both insert and delete records shud be deleted from teh actual file.

so the final shud be like


Below three records shud go to reject file

The file will have few thousand records every day,any such shell script would be very helpful.

Thanks in advance

Last edited by bartus11; 03-29-2014 at 05:43 AM.. Reason: Please use [code][/code] tags.
# 2  
Old 03-29-2014
Hi guy,
May this a not very good method.
awk '$2=="I"{I[$3$4]=$0}$2=="U"&&!I[$3$4]{U[$3$4]=$0}$2=="D"{if(I[$3$4]){delete I[$3$4]}else{D[$3$4]=$0}}
END{{for(i in I){print I[i]}}{for(u in U){print U[u]}}{for(d in D){print D[d]}}}' FS='|' file

# 3  
Old 04-03-2014
Thanku very much Lucas_0418,

Can u please explain how exactly this works
# 4  
Old 04-03-2014
You should be asking what bit of awk you did not understand, or show what you did understand - and what you are missing here
# 5  
Old 04-04-2014

I do understand the script overall ,but how to redirect the deleting records into a file in thi script

---------- Post updated at 03:02 PM ---------- Previous update was at 02:53 PM ----------

Thanks for the script a lot ...only i thing i require additional to the script is redirect the records (which doesn't satisfy the conditions ) to a .REJ file.

Thanks in advance.
# 6  
Old 04-07-2014
Hi Guys ,

Any help on this ....i cant move the rejected records to another file..
Please help

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with Shell Scrip in Masking particular columns in .csv file or .txt file using shell script

Hello Unix Shell Script Experts, I have a script that would mask the columns in .csv file or .txt file. First the script will untar the .zip files from Archive folder and processes into work folder and finally pushes the masked .csv files into Feed folder. Two parameters are passed ... (5 Replies)
Discussion started by: Mahesh G
5 Replies

2. Shell Programming and Scripting

incorporating a regular expression statement in a shell script (.sh)

I do have a shell file where I call many unix commands . I would like to add a regular expression step in that shell file, where a text file, say Test.txt has to be openned and all the :'s should be replaced. Basically apply the follwoing regular expression: :%s/://g to that particular text... (2 Replies)
Discussion started by: Lucky Ali
2 Replies

3. Shell Programming and Scripting

regular expression with shell script to extract data out of a text file

hi i am trying to extract some specific data out of a text file using regular expressions with shell script that is using a multiline grep .. and the tool i am using is pcregrep so that i can get compatibility with perl's regular expressions for a sample data like this, i am trying to grab... (6 Replies)
Discussion started by: vemkiran
6 Replies

4. Programming

Perl: How to read from a file, do regular expression and then replace the found regular expression

Hi all, How am I read a file, find the match regular expression and overwrite to the same files. open DESTINATION_FILE, "<tmptravl.dat" or die "tmptravl.dat"; open NEW_DESTINATION_FILE, ">new_tmptravl.dat" or die "new_tmptravl.dat"; while (<DESTINATION_FILE>) { # print... (1 Reply)
Discussion started by: jessy83
1 Replies

5. Shell Programming and Scripting

Need help in Regular expression in bash shell

hi, I have written a script to search MAC address in a given directory. MAC address would be in format XX.XX.XX.XX. The digits contain hexadecimal numbers. For this i have used grep as follows. grep -rn '^\{1,2\}\.\{1,2\}\.\{1,2\}\.\{1,2\}\$' * This is not working as required.... (17 Replies)
Discussion started by: flamingo_l
17 Replies

6. Shell Programming and Scripting

Regular Expressions in K Shell Script

I need to write a K shell script to find full file names , line numbers and lines which have words meeting either of following 2 criterias - 1)words which are 6 to 8 character long and alphanumeric. 2)Minimum 8 characters, one upper case, one lower case letter, one of the special characters... (1 Reply)
Discussion started by: Rajpreet1985
1 Replies

7. Shell Programming and Scripting

problem with Regular expression as input in shell script

Hi, I have script which will take a string as input and search in a file. But when I want to search a pattern which has special characters script is ignoring it. For example: I want to search a pattern "\.tumblr\.com". shell script is removing \ (backslah) and trying to search... (7 Replies)
Discussion started by: Anjan1
7 Replies

8. Shell Programming and Scripting

how to read dbf file in shell script and to convert dbf file usinf shell script

Hi all, I am new to shell scripting. I have dbf file and I need to convert it into csv file. OR, can i read the fields from a .dbf file and OR seprate the records in dbf file and put into .csv or txt. Actually in the .dbf files I am getting , the numbers of fields may vary in very record and... (6 Replies)
Discussion started by: gauara
6 Replies

9. UNIX for Dummies Questions & Answers

Execute a shell script using regular expressions

I am have a configuration script that my shell script uses. There is a regular expression defined for the input file. How do execute the shell script and pass the name of the input file using a regular expression. I would greatly appreciate some help. If you could point my to a website that... (1 Reply)
Discussion started by: supergirl3954
1 Replies

10. Shell Programming and Scripting

using regular expression an shell script!!

I want to check if the first argument of my shell script starts with a specifiec string? Any Idea?? Thank u (3 Replies)
Discussion started by: andy2000
3 Replies
Login or Register to Ask a Question