Patterns
Line-based
New Scripts
1
Print `ODD' if there are odd number of lines containing
PAT
in the datafile.
2008.06.23
Two Patterns
1
Get lines containing
PAT
1
AND
PAT
2
of a file.
2000.11.16
2
Get lines containing
PAT
1
OR
PAT
2
of a file.
2000.11.17
3
Get lines containing
PAT
1
but no
PAT
2
of a file.
2000.09.29
4
Insert a separating line after a line beginning with 'abc' and immediately followed by a line beginning with 'xyz'.
2005.07.29
5
Perform operations on lines starting from the fist line containing
PAT
1
till the last one containing
PAT
2
.
2008.01.24
Two Consecutive Lines
1
Delete two consecutive lines if the first one contains
PAT
1
1, and the second one contains
PAT
2
.
2007.12.31
2
Remove almost identical lines.
2008.01.21
Lines Containing
PAT
and their Neighbors.
1
Get every line containing
PAT
and the adjacent one preceding it.
2008.02.09
2
Get every line containing
PAT
and lines adjacent to it.
2001.02.15
3
Get lines containing
PAT
and 3 consecutive lines following each of them.
2000.11.15
4
Get every line which is adjacent to and precedes a line containing
PAT
.
2001.02.13
5
Get the line following a line containing
PAT
.
2004.02.17
6
Delete lines containing
PAT
and the 2 next lines following them.
2006.07.17
7
Extract 'Received:' headers from a mailbox.
2004.05.16
N-th Line Containing
PAT
1
Get the N-th matched line.
2007.08.23
2
Get the N-th matched line.(another version)
2007.09.03
First Line Containing
PAT
1
Get the FIRST line containing
PAT
2000.09.29
2
Delete the FIRST line containing
PAT
of a file.
2000.09.29
3
Get lines starting from the FIRST one containing
PAT
till the end of file.
2000.10.18
4
Delete up to, but not including, the first line containing
PAT
.
2001.02.17
Last Line Containing
PAT
1
Get the LAST line containing
PAT
of a file.
2000.10.04
2
Delete the LAST line containing
PAT
of a file.
2000.10.04
3
Get the lines from the last one containing
PAT
of a file.
2006.06.22
4
Get the lines after the last one containing
PAT
of a file.
2006.06.28
5
Delete the lines from the last line containing
PAT
till the end of file.
2006.07.19
6
Delete the lines till the last one containing
PAT
.
2007.09.05
7
Perform a specific operation on lines starting from the beginning of a file till the last line containing
PAT
.
2007.01.18
Append/Join Conditionally
1
If a line does not end with a dot ('.'), join every following line till one ending with a dot.
2001.02.26
2
A case study on joining lines.
2004.09.29
3
Join every three non-blank lines to one line, separate them by '|'s.
2004.02.12
4
Append a line to the previous one if it does not begin with some tag.
2006.09.13
Reformat a File
1
Split lines that are longer than 25 characters.
2001.06.22
2
Move lines containing some string to the end of a file.
2002.12.04
3
Fix newlines at wrong positions.
2004.03.04
4
Add a separator line to the end of every 'block'.
2002.10.04
5
Append a message after very 'block'.
2004.09.10
6
If a non-blank line is not followed by a blank line, append a <br> tag to the end of it.
2006.05.22
7
Show complete records only.
2007.06.12
Misc
1
Get the longest line of a file.
2000.10.11
2
Remove consecutive duplicate lines.
2008.02.21
3
Retrieve IPs and interface names from the output of /sbin/ifconfig.
2003.02.21
4
Comment out uncommented lines.
2004.02.27
5
Prepend the contents of some file before every matching line of a file.
2005.10.18
6
Print the last line of each group consisting of lines with the same tag.
2003.01.28
7
Replace every instance of 'KEY=....' of a file with the first one.
2004.06.08