# # A sed example # <2019-06-19 15:26:23 cmic> # After running algorithm A on a lot of data, I end up with a large list of files like dataset-directory/0001_data.csv dataset-directory/0002_data.csv dataset-directory/0002_A.csv dataset-directory/0003_data.csv dataset-directory/0003_A.csv dataset-directory/0004_data.csv dataset-directory/0005_data.csv dataset-directory/0005_A.csv .. The astute observer will note that the file for algorithm A on data 0001 and 0004 are missing. How can I get a list of all the numbers for which A didn’t succeed? So all together this gives the following ls | sed '/A/{N;d;}' #N appends a \n and next line to pattern space; #d delete pattern space and start a new cycle NB: Lines from input stream are placed into the pattern space (where they can be modified) and then pattern space is sent to output stream. The hold spce can be used for temporary storage. NB: - n or N read/append input to patern space - d delete the pattern space and start a new cycle - h (or H) copy pattern space to hold space - g (or G) copy hold space to pattern space - x exchange pattern space and hold space See also https://catonmat.net/sed-one-liners-explained-part-one and https://catonmat.net/sed-one-liners-explained-part-two and man sed RTFM !!