logging deleted records by sed


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers logging deleted records by sed
# 1  
Old 01-23-2009
logging deleted records by sed

Hi,

I want to use the sed command to delete some lines in a file and I was wondering whether there is a possibility of knowing which lines are deleted, or at least which line numbers.

Thanks
# 2  
Old 01-23-2009
Maybe it's easier with awk for a job like this. What are the conditions to delete a line?

Regards
# 3  
Old 01-23-2009
Hi,

I'm not familiar with awk, but if that's better then fine!

Basically I need to delete any lines which contains records from a SQL output.

Here is what I started coding (I'm posting only the part I need help with):


...
sqlplus -s $APPS_USR/$APPS_PWD <<ENDOFSQL
SET HEADING OFF;
SET FEEDBACK OFF;
SET LINESIZE 300;
SELECT banque, guichet, compte
FROM (select abb.bank_number banque,
abb.bank_num guichet,
abaa.bank_account_num compte,
rbi.import_date date_dernier_import,
row_number() over (partition by rbi.bank_account_id order by rbi.import_date desc) rn
from ap.ap_bank_accounts_all abaa,
ap.ap_bank_branches abb,
rb.rb_bank_accounts_all rbaa,
rb.rb_batch_import rbi
where rbaa.bank_account_id = abaa.bank_account_id
and abb.bank_branch_id = abaa.bank_branch_id
and rbi.bank_account_id = rbaa.bank_account_id
and rbaa.status = 'Y'
)
WHERE rn = 1
AND date_dernier_import > add_months(sysdate, -2);
ENDOFSQL
} | while read ligne
do
if [ "$ligne" ] # Ligne non NULL
then
set $ligne
banque="$1"
guichet="$2"
compte="$3"

sed '/'"$banque"'.*'"$guichet"'.*'"compte"'/ !d' < $fich_src > $fich_dest
cp $fich_dst $fich_src
fi
done
...

So I'd like to log which line numbers have been deleted.

Thanks
# 4  
Old 01-23-2009
You also can use a grep command between the sed and cp command in this case (output in "deleted.log"):

Code:
sed '/'"$banque"'.*'"$guichet"'.*'"compte"'/ !d' < $fich_src > $fich_dest
grep -v -n -f $fich_dest $fich_src > deleted.log
cp $fich_dst $fich_src

Instead of the sed command you can try this with awk (not tested), the deleted lines are in the file "deleted.log":

Code:
awk '/'"$banque"'.*'"$guichet"'.*'"$compte"'/{print;next}{print NR, $0> "deleted.log"' < $fich_src > $fich_dest

Regards
# 5  
Old 01-23-2009
I hadn't thought of using grep just after to identify deleted records.

Thanks!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

Syslog not logging successful logging while unlocking server's console

When unlocking a Linux server's console there's no event indicating successful logging Is there a way I can fix this ? I have the following in my rsyslog.conf auth.info /var/log/secure authpriv.info /var/log/secure (1 Reply)
Discussion started by: walterthered
1 Replies

2. Shell Programming and Scripting

Display records between two search strings using sed

I have input file like AAA AAA CCC CCC CCC EEE EEE EEE EEE FFF FFF GGG GGG i was trying to retrieve data between two strings using sed. sed -n /CCC/,/FFF/p input_file Am getting output like CCC CCC CCC (1 Reply)
Discussion started by: NareshN
1 Replies

3. UNIX for Dummies Questions & Answers

Turning to SED to select specific records

Hi All, I am looking for a simple concise solution most likely using sed to process the following 4 rows of data from the same record and only keeps it if the second record satisfy certain critea such as surname matches up to smith or jackson: John (firstname) Smith (surname) ... (21 Replies)
Discussion started by: gjackson123
21 Replies

4. Shell Programming and Scripting

sed delete but save deleted output into other file

Hi guys, I am currently using this to save first 50 lines into top50.txt and delete them from list.txt ... it's 2 commands: head -n 50 list.txt > top50.txt && sed -i "1,50 d" list.txt I want to change that so it's 1 command - whereby sed removes the first 50 lines as above but that which is... (3 Replies)
Discussion started by: holyearth
3 Replies

5. Shell Programming and Scripting

Finding some records with sed command

Hi for all! sorry guys for my dumb question, but I'm really need help so, we have file with many many fields, like this one: 201001002359 blablabla 87654321 201001002359 123,56 77272588300 blablabla/123 91823778544and I wrote awk command awk '{if($6~/(2588300|2580000|2587021)$/)print}'so,... (8 Replies)
Discussion started by: shizik
8 Replies

6. Shell Programming and Scripting

deleting text records with sed (sed paragraphs)

Hi all, First off, Thank you all for the knowledge I have gleaned from this site! Deleting Records from a text file... sed paragraphs The following code works nearly perfect, however each time it is run on the log file it adds a newline at the head of the file, run it 5 times, it'll have 5... (1 Reply)
Discussion started by: Festus Hagen
1 Replies

7. Shell Programming and Scripting

How to replicated records using sed

I need to generate exactly 102 duplicates in a file using sed. Here's an example of my input: Grid-ref = 1, 148 Grid-ref = 1, 311 Grid-ref = 1, 428 I need: Grid-ref = 1, 148 Grid-ref = 1, 148 Grid-ref = 1, 148 Grid-ref = 1, 148 ... repeated 102 times, then Grid-ref = 1, 311... (2 Replies)
Discussion started by: Russ
2 Replies

8. Shell Programming and Scripting

sed problem - last line of file deleted

Hi, I am simply trying to remove the header row from a file using sed, but I'm running into strange difficulties. It seems that in addition to removing the first line, this command is also removing the last line (or more specifically, clearing the last line, since the line is still counted... (4 Replies)
Discussion started by: erichpowell
4 Replies

9. Shell Programming and Scripting

How to delimit a flat file with records with SED

Hi gurus, hoping someone can help with a sed line that can do the following... I have a flat file with about 1000 records, but in order to import into openoffice spreadsheet, I need to create a delimited file. I'd like to do 2 things with the SED command: 1- add a pipe character "|" at the end... (4 Replies)
Discussion started by: RogCor
4 Replies

10. UNIX for Dummies Questions & Answers

Help comparing 2 files to find deleted records

Hi, I need to compare todays file to yesterdays file to find deletes. I cannot use comm -23 file.old file.new. Because each record may have a small change in it but is not really a delete. I have two delimited files. the first field in each file is static. All other fields may change. I... (2 Replies)
Discussion started by: eja
2 Replies
Login or Register to Ask a Question