Skip to content

Instantly share code, notes, and snippets.

@icelander
Created January 21, 2022 20:01
Show Gist options
  • Save icelander/dcaf7988d17f819c51b768dd4dca7a26 to your computer and use it in GitHub Desktop.
Save icelander/dcaf7988d17f819c51b768dd4dca7a26 to your computer and use it in GitHub Desktop.
This is a simple script that removes a specific line from a file
#!/bin/bash
##
# remove_line.sh
##
# About
#
# This is a simple script that removes a given line from a file. When run it
# will create a file named
##
# Usage
#
# remove_line.sh <path to file> <line to remove>
##
# Example
#
# Command:
#
# remove_line.sh import.jsonl 343
#
# Result
#
# A file named import.jsonl.without-343 is created without line 343 from
# import.jsonl
the_file=$1
invalid_line=$2;
the_filename=`basename $the_file`
new_filename="$the_filename.without-$invalid_line"
echo "Creating file $new_filename"
head -n$((invalid_line-1)) $the_file > $new_filename;
tail -n+$((invalid_line+1)) $the_file >> $new_filename;
echo "Complete!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment