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 October 2025

1 Autel IM508S Better Than Autel KM100 Scanner & Programmer Tool Full OBDII Diagnostics Code Readers Level-up of IM508 Diagnostics Scan Tool Programming with XP200

Autel IM508S Better Than Autel KM100 Scanner & Programmer Tool Full OBDII Diagnostics Code Readers Level-up of IM508 Diagnostics Scan Tool Programming with XP200

  • OE-LEVEL DIAGNOSTICS FOR 15,000+ MODELS GLOBALLY.

  • DUAL MODES FOR EXPERT AND SMART USER FLEXIBILITY.

  • COMPREHENSIVE 40+ SERVICE FUNCTIONS FOR MODERN VEHICLES.

BUY & SAVE
$1,199.00
Autel IM508S Better Than Autel KM100 Scanner & Programmer Tool Full OBDII Diagnostics Code Readers Level-up of IM508 Diagnostics Scan Tool Programming with XP200
2 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 SERVICE: 20+ HOT MAINTENANCE SERVICES FOR DIY AUTO CARE.

  • COST-EFFECTIVE SOLUTION: SAVE $100+ ON DIAGNOSTICS WITH SC530 PRO.

  • LIFETIME UPDATES: FREE UPDATES ENSURE YOUR TOOL STAYS CURRENT FOREVER.

BUY & SAVE
$113.97 $168.97
Save 33%
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
3 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 & MONEY: QUICKLY READ AND ERASE ENGINE FAULT CODES AT HOME!

  • FULL OBDII COVERAGE: ADVANCED DIAGNOSTICS FOR ALL ENGINE SYSTEMS INCLUDED.

  • USER-FRIENDLY DESIGN: EASY PLUG-AND-PLAY WITH UNIVERSAL VEHICLE COMPATIBILITY!

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)
4 Autel Bidirectional Obd2 Scanner MaxiCOM MK808Z, 2025 All System Diagnostic Scan Tool, Universal OBDII Vehicle Code Reader, Same As MK808BT Pro MX808S MK808S,28+ Service, with MV108S Endoscope

Autel Bidirectional Obd2 Scanner MaxiCOM MK808Z, 2025 All System Diagnostic Scan Tool, Universal OBDII Vehicle Code Reader, Same As MK808BT Pro MX808S MK808S,28+ Service, with MV108S Endoscope

  • SEAMLESS DIAGNOSTICS WITH ANDROID 11 & UPGRADED PROCESSOR.

  • BIDIRECTIONAL CONTROL BOOSTS EFFICIENCY BY 50%-NO DISASSEMBLY NEEDED!

  • 28+ PROFESSIONAL SERVICES COVER ALL KEY MAINTENANCE NEEDS EASILY.

BUY & SAVE
$479.00
Autel Bidirectional Obd2 Scanner MaxiCOM MK808Z, 2025 All System Diagnostic Scan Tool, Universal OBDII Vehicle Code Reader, Same As MK808BT Pro MX808S MK808S,28+ Service, with MV108S Endoscope
5 KINGBOLEN OBD2 Scanner S800 Car Scanner, OBD2 Diagnostic Scan Tool with 15 Reset, Oil Brake Throttle Service, Engine ABS SRS Transmission Code Reader, Battery Test, AutoVIN, Lifetime Fr-ee Update

KINGBOLEN OBD2 Scanner S800 Car Scanner, OBD2 Diagnostic Scan Tool with 15 Reset, Oil Brake Throttle Service, Engine ABS SRS Transmission Code Reader, Battery Test, AutoVIN, Lifetime Fr-ee Update

  • USER-FRIENDLY DESIGN: 5 TOUCHSCREEN, RECHARGEABLE, EASY OPERATION.
  • MULTI-SYSTEM DIAGNOSTICS: FULL OBD2 FUNCTIONS FOR COMPREHENSIVE VEHICLE HEALTH.
  • LIFETIME FREE UPDATES: NO SUBSCRIPTION, CONTINUOUS IMPROVEMENTS FOR USERS.
BUY & SAVE
$169.99 $189.99
Save 11%
KINGBOLEN OBD2 Scanner S800 Car Scanner, OBD2 Diagnostic Scan Tool with 15 Reset, Oil Brake Throttle Service, Engine ABS SRS Transmission Code Reader, Battery Test, AutoVIN, Lifetime Fr-ee Update
6 Hands-On Data Visualization: Interactive Storytelling From Spreadsheets to Code

Hands-On Data Visualization: Interactive Storytelling From Spreadsheets to Code

BUY & SAVE
$36.49 $65.99
Save 45%
Hands-On Data Visualization: Interactive Storytelling From Spreadsheets to Code
7 Yourkar Collapsible Magnetic Parts Tray, 4.5 Inch Foldable Magnetic Square Silicone Tray, Tool Tray Set with Double-Sided Magnetic Base for Screw Bolts Nuts Pins, Car Accessories (Black+Purple, 2PCS)

Yourkar Collapsible Magnetic Parts Tray, 4.5 Inch Foldable Magnetic Square Silicone Tray, Tool Tray Set with Double-Sided Magnetic Base for Screw Bolts Nuts Pins, Car Accessories (Black+Purple, 2PCS)

  • DURABLE SILICONE: SCRATCH-RESISTANT, WEATHERPROOF FOR LASTING USE.

  • STRONG MAGNETIC BASE: DOUBLE-SIDED DESIGN HOLDS MORE METAL PARTS SECURELY.

  • SPACE-SAVING DESIGN: FOLDABLE FOR EASY STORAGE AND PORTABILITY ANYWHERE.

BUY & SAVE
$9.49 $9.99
Save 5%
Yourkar Collapsible Magnetic Parts Tray, 4.5 Inch Foldable Magnetic Square Silicone Tray, Tool Tray Set with Double-Sided Magnetic Base for Screw Bolts Nuts Pins, Car Accessories (Black+Purple, 2PCS)
8 Cosmic Codes: Hidden Messages From The Edge Of Eternity: Bible Codes

Cosmic Codes: Hidden Messages From The Edge Of Eternity: Bible Codes

BUY & SAVE
$1.99
Cosmic Codes: Hidden Messages From The Edge Of Eternity: Bible Codes
9 EASTDEER Gym Locker Lock 4 Digit Combination Lock for Locker for School Gym Lock for Sports, Toolbox, Case, Hasp Storage(20) (Shackle Black)

EASTDEER Gym Locker Lock 4 Digit Combination Lock for Locker for School Gym Lock for Sports, Toolbox, Case, Hasp Storage(20) (Shackle Black)

  • KEYLESS SECURITY: 4-DIGIT COMBO LOCK FOR SHARED FAMILY USE-NO LOST KEYS!

  • EASY READ IN DARK: OVERSIZED BOLD NUMBERS FOR QUICK VISIBILITY, DAY OR NIGHT.

  • COMPACT & VERSATILE: FITS GYM LOCKERS AND TOOLBOXES-STRONG, DURABLE DESIGN!

BUY & SAVE
$8.54
EASTDEER Gym Locker Lock 4 Digit Combination Lock for Locker for School Gym Lock for Sports, Toolbox, Case, Hasp Storage(20) (Shackle Black)
+
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.