Skip to main content
ubuntuask.com

Back to all posts

How to Delete Added (Not Modified) Lines Between Two Files In Bash?

Published on
3 min read
How to Delete Added (Not Modified) Lines Between Two Files In Bash? image

Best Code Comparison Tools to Buy in November 2025

1 BLCKTEC 430 Bluetooth OBD2 Scanner for iPhone & Android, No Subscription Fee, OBDII Car Code Reader, Diagnose Check Engine, ABS, SRS, Airbag, Supports Vehicles 1996+

BLCKTEC 430 Bluetooth OBD2 Scanner for iPhone & Android, No Subscription Fee, OBDII Car Code Reader, Diagnose Check Engine, ABS, SRS, Airbag, Supports Vehicles 1996+

  • TRANSFORM CAR CARE: BECOME YOUR OWN MECHANIC WITH EFFORTLESS DIAGNOSTICS.

  • COMPREHENSIVE DIAGNOSTICS: ACCESS ADVANCED VEHICLE INSIGHTS AT YOUR FINGERTIPS.

  • FULL ACCESS, NO FEES: ONE PURCHASE GRANTS UNLIMITED FEATURES; NO HIDDEN COSTS.

BUY & SAVE
$62.99 $69.99
Save 10%
BLCKTEC 430 Bluetooth OBD2 Scanner for iPhone & Android, No Subscription Fee, OBDII Car Code Reader, Diagnose Check Engine, ABS, SRS, Airbag, Supports Vehicles 1996+
2 TOPDON AD800BT 2 OBD2 Scanner, 2025 Bidirectional Scan Tool, Function as AD900 Lite AD Pro, All System Automotive Diagnostic Scanner, Active Test, 28+ Reset Service, FCA Autoauth, 2 Years Free Update

TOPDON AD800BT 2 OBD2 Scanner, 2025 Bidirectional Scan Tool, Function as AD900 Lite AD Pro, All System Automotive Diagnostic Scanner, Active Test, 28+ Reset Service, FCA Autoauth, 2 Years Free Update

  • BIDIRECTIONAL CONTROL FOR ACCURATE DIAGNOSTICS & MAINTENANCE
  • ACCESS 28 POPULAR RESET SERVICES WITH USER-FRIENDLY GUIDANCE
  • COMPATIBLE WITH 96 VEHICLE BRANDS FOR VAST APPLICATION
BUY & SAVE
$379.00
TOPDON AD800BT 2 OBD2 Scanner, 2025 Bidirectional Scan Tool, Function as AD900 Lite AD Pro, All System Automotive Diagnostic Scanner, Active Test, 28+ Reset Service, FCA Autoauth, 2 Years Free Update
3 CGSULIT SC530 Pro OBD2 Scanner Diagnostic Scan Tool for Mercedes Benz, 2025 Full System Car Code Reader with 20+ Services, ABS Bleed, Oil/EPB/SRS/SAS/TCM/BMS/T-hrottle Reset, Auto VIN, Free Update

CGSULIT SC530 Pro OBD2 Scanner Diagnostic Scan Tool for Mercedes Benz, 2025 Full System Car Code Reader with 20+ Services, ABS Bleed, Oil/EPB/SRS/SAS/TCM/BMS/T-hrottle Reset, Auto VIN, Free Update

  • COMPREHENSIVE MAINTENANCE SERVICES: 20+ FUNCTIONS TO HANDLE DAILY NEEDS.

  • LIFETIME FREE UPDATES: NO FEES, CONTINUOUS ENHANCEMENTS FOR YOUR SCANNER.

  • COST-EFFECTIVE SOLUTION: SAVE HUNDREDS ON REPAIRS; PAY ONLY $115 ONCE!

BUY & SAVE
$128.77 $168.97
Save 24%
CGSULIT SC530 Pro OBD2 Scanner Diagnostic Scan Tool for Mercedes Benz, 2025 Full System Car Code Reader with 20+ Services, ABS Bleed, Oil/EPB/SRS/SAS/TCM/BMS/T-hrottle Reset, Auto VIN, Free Update
4 KINGBOLEN OBD2 Scanner S500 Car Scanner, Lifetime NO Cost Update Diagnostic Scan Tool with 6 Reset,Oil/Brake/SAS/Throttle/Inject/ABS Reset, Engine ABS SRS Transmission OBD2 Code Reader, Battery Test

KINGBOLEN OBD2 Scanner S500 Car Scanner, Lifetime NO Cost Update Diagnostic Scan Tool with 6 Reset,Oil/Brake/SAS/Throttle/Inject/ABS Reset, Engine ABS SRS Transmission OBD2 Code Reader, Battery Test

  • LIFETIME UPDATES: NO SUBSCRIPTION FEES; ENJOY ONGOING SOFTWARE UPGRADES.

  • MULTI-SYSTEM DIAGNOSTICS: READS/CODES FOR ENGINE, ABS, SRS, AND MORE!

  • USER-FRIENDLY DESIGN: 5 SCREEN & RECHARGEABLE BATTERY FOR EASY USE.

BUY & SAVE
$149.99
KINGBOLEN OBD2 Scanner S500 Car Scanner, Lifetime NO Cost Update Diagnostic Scan Tool with 6 Reset,Oil/Brake/SAS/Throttle/Inject/ABS Reset, Engine ABS SRS Transmission OBD2 Code Reader, Battery Test
5 Autel Scanner MaxiCOM MK808BT PRO, 2025 2.0 Full Bidirectional Diagnostic Tool as MK900 MX900 MK900BT, Pro Ver. of MK808S MX808S, 3000+ Test, 28+ Service, All System, Brake Bleed, Injector Coding, FCA

Autel Scanner MaxiCOM MK808BT PRO, 2025 2.0 Full Bidirectional Diagnostic Tool as MK900 MX900 MK900BT, Pro Ver. of MK808S MX808S, 3000+ Test, 28+ Service, All System, Brake Bleed, Injector Coding, FCA

  • VEHICLE-SPECIFIC FUNCTIONS: ALWAYS SEND VIN FOR COMPATIBILITY CHECKS!
  • UNMATCHED ACTIVE TESTS: OVER 3000 TESTS FOR EFFICIENT DIAGNOSTICS!
  • 33FT WIRELESS RANGE: EXPERIENCE FREEDOM WITH BLUETOOTH TECHNOLOGY!
BUY & SAVE
$549.00
Autel Scanner MaxiCOM MK808BT PRO, 2025 2.0 Full Bidirectional Diagnostic Tool as MK900 MX900 MK900BT, Pro Ver. of MK808S MX808S, 3000+ Test, 28+ Service, All System, Brake Bleed, Injector Coding, FCA
6 KONNWEI KW850 Professional OBD2 Scanner Auto Code Reader Diagnostic Check Engine Light Scan Tool for OBD II Cars After 1996(Original)

KONNWEI KW850 Professional OBD2 Scanner Auto Code Reader Diagnostic Check Engine Light Scan Tool for OBD II Cars After 1996(Original)

  • SAVE TIME AND MONEY BY DIAGNOSING ISSUES WITHOUT A DEALER VISIT!
  • USER-FRIENDLY TOOL WITH REAL-TIME DATA FOR QUICK FAULT IDENTIFICATION.
  • WORKS ON MOST VEHICLES; PLUG AND PLAY-NO APPS OR BATTERIES NEEDED!
BUY & SAVE
$89.99
KONNWEI KW850 Professional OBD2 Scanner Auto Code Reader Diagnostic Check Engine Light Scan Tool for OBD II Cars After 1996(Original)
7 Autel Scanner MaxiCOM MK900BT, 2025 MK900-BT Bidirectional Diagnostic Scan Tool, 2.0 BT Ver. of MK900 MX900, 8in Up of MK808S MK808BT PRO MX808S MK808Z, 40+ Reset, 3K+ Active Tests, CAN FD & DoIP, FCA

Autel Scanner MaxiCOM MK900BT, 2025 MK900-BT Bidirectional Diagnostic Scan Tool, 2.0 BT Ver. of MK900 MX900, 8in Up of MK808S MK808BT PRO MX808S MK808Z, 40+ Reset, 3K+ Active Tests, CAN FD & DoIP, FCA

  • 40+ SERVICES & 3000+ ACTIVE TESTS FOR ULTIMATE DIAGNOSTIC PRECISION!

  • FAST WIFI PRINTING & NEW AUTO SCAN 2.0 - SCANS IN SECONDS!

  • BIDIRECTIONAL CONTROL WITH ADVANCED FEATURES FOR 150+ CAR MAKES!

BUY & SAVE
$659.00
Autel Scanner MaxiCOM MK900BT, 2025 MK900-BT Bidirectional Diagnostic Scan Tool, 2.0 BT Ver. of MK900 MX900, 8in Up of MK808S MK808BT PRO MX808S MK808Z, 40+ Reset, 3K+ Active Tests, CAN FD & DoIP, FCA
8 FOXWELL NT1009 All-System Bi-Directional Scan Tool with All Reset Services, Topology Mapping, V.A.G Guide & FCA SGW Support, CAN-FD DoIP Diagnostic Scanner for All Cars, 3-Year Free Updates

FOXWELL NT1009 All-System Bi-Directional Scan Tool with All Reset Services, Topology Mapping, V.A.G Guide & FCA SGW Support, CAN-FD DoIP Diagnostic Scanner for All Cars, 3-Year Free Updates

  • FAST WIRELESS ALL-SYSTEM DIAGNOSIS-50% QUICKER THAN BLUETOOTH!

  • COMPLETE MAINTENANCE RESETS-NO EXTRA TOOLS NEEDED! SAVE COSTS!

  • BI-DIRECTIONAL CONTROL & HIDDEN FEATURES-BOOST SALES BY 30%!

BUY & SAVE
$899.00
FOXWELL NT1009 All-System Bi-Directional Scan Tool with All Reset Services, Topology Mapping, V.A.G Guide & FCA SGW Support, CAN-FD DoIP Diagnostic Scanner for All Cars, 3-Year Free Updates
9 2025 Autel ML629 OBD2 Scanner ABS SRS Engine Transmission Diagnoses OBD II Full Functions Upgraded Version of AL519/AL619/ ML619 for DIYers Professionals

2025 Autel ML629 OBD2 Scanner ABS SRS Engine Transmission Diagnoses OBD II Full Functions Upgraded Version of AL519/AL619/ ML619 for DIYers Professionals

  • DIAGNOSE 4 SYSTEMS AND TURN OFF WARNING LIGHTS FOR SAFER DRIVING.

  • ACCESS 10 OBDII TEST MODES FOR ACCURATE FAULT DETECTION AND REPAIRS.

  • BUILT-IN DTC LIBRARY FOR FAST CODE DEFINITIONS-NO SEARCHING NEEDED!

BUY & SAVE
$126.88
2025 Autel ML629 OBD2 Scanner ABS SRS Engine Transmission Diagnoses OBD II Full Functions Upgraded Version of AL519/AL619/ ML619 for DIYers Professionals
+
ONE MORE?

To delete added lines between two files in bash, you can use the diff command to compare the two files and then use grep to filter out the added lines. You can do this by running the following command:

diff file1.txt file2.txt | grep '^> ' | cut -c3- | comm -23 - <(sort -u file1.txt) | sed '/^>/d' > deleted_lines.txt

This command will compare file1.txt and file2.txt, filter out the added lines using grep, exclude the common lines between the two files using comm, remove the leading > from the added lines using sed, and finally save the deleted lines to deleted_lines.txt.

What is the utility to delete added lines between two files in bash?

The diff command can be used to compare two files and find the differences between them, including any added lines. To delete the added lines between two files in bash, you can use the following command:

diff file1 file2 | grep -E '^>' | sed 's/^> //' | while IFS= read -r line; do sed -i "/$line/d" file2; done

This command compares the two files file1 and file2, extracts the added lines using grep, removes the > symbol at the beginning of each line using sed, and then deletes those lines from file2 using another sed command within a loop.

How to automate the process of removing added lines between two files in bash?

You can automate the process of removing added lines between two files in bash by using the diff command to find the differences between the two files and then using the sed command to remove the added lines.

Here's a simple example of how you can achieve this:

  1. Use the diff command to find the differences between the two files:

diff file1.txt file2.txt > diff.txt

  1. Use the sed command to remove the added lines from file2.txt:

sed -e 's/^>.*$//' diff.txt | sed -e '/^</d' > removed_lines.txt

This will create a new file removed_lines.txt that contains only the lines that were added in file2.txt.

You can also combine these two commands into a single line using pipes:

diff file1.txt file2.txt | sed -e 's/^>.*$//' | sed -e '/^</d' > removed_lines.txt

Make sure to replace file1.txt and file2.txt with the actual file names that you want to compare.

What is the process for removing added lines between two files in bash?

To remove added lines between two files in bash, you can use the diff command to identify the differences between the two files and then use the patch command to apply the differences to one of the files. Here is the process in more detail:

  1. Use the diff command to generate a diff file containing the added lines between the two files:

diff file1.txt file2.txt > added_lines.diff

  1. Use the patch command to apply the diff file to one of the files:

patch file1.txt < added_lines.diff

This will remove the added lines from file1.txt that are present in file2.txt.

Note: Make sure to create backups of your files before making any changes to them using diff and patch commands.