Sed

Sed

Remove the 1st line

sed 1d filename

Remove the first 100 lines (remove line 1-100)

sed 1,100d filename

Remove lines with string (e.g. 'bbo')

sed "/bbo/d" filename
# case insensitive:
sed "/bbo/Id" filename

Remove lines whose nth character not equal to a value (e.g. 5th character not equal to 2)

sed -E '/^.{5}[^2]/d'
#aaaa2aaa (you can stay)
#aaaa1aaa (delete!)

Edit infile (edit and save to file), (e.g. deleting the lines with 'bbo' and save to file)

When using variable (e.g. $i), use double quotes " "

Using environment variable and end-of-line pattern at the same time.

Delete/remove empty lines

Delete/remove last line

Delete/remove last character from end of file

Add string to beginning of file (e.g. "[")

Add string at certain line number (e.g. add 'something' to line 1 and line 3)

Add string to end of file (e.g. "]")

Add newline to the end

Add string to beginning of every line (e.g. 'bbo')

Add string to end of each line (e.g. "}")

Add \n every nth character (e.g. every 4th character)

Concatenate/combine/join files with a seperator and next line (e.g separate by ",")

Substitution (e.g. replace A by B)

Substitution with wildcard (e.g. replace a line start with aaa= by aaa=/my/new/path)

Select lines start with string (e.g. 'bbo')

Delete lines with string (e.g. 'bbo')

Remove leading whitespace and tabs

Remove only leading whitespace

Remove ending commas

Add a column to the end

Add extension of filename to last column

Remove newline\ nextline

Change delimiter

Replace with wildcard (e.g A-1-e or A-2-e or A-3-e....)

Remove last character of file

Insert character at specified position of file (e.g. AAAAAA --> AAA#AAA)

Last updated

Was this helpful?