Skip to content

Instantly share code, notes, and snippets.

@silvtal
Last active March 16, 2022 16:46
Show Gist options
  • Save silvtal/f564c4fe8841174b643cbbb300fed8ad to your computer and use it in GitHub Desktop.
Save silvtal/f564c4fe8841174b643cbbb300fed8ad to your computer and use it in GitHub Desktop.
Splits a fixedStep .wig file at its headers
#!/bin/bash
## BASED ON : https://www.baeldung.com/linux/split-file-at-line-numbers
INPUT_FILE="out/experimental_reads.wig" # The input file
LINE_NUMBERS=( $(cat $INPUT_FILE | grep -n "g" | cut -f 1 -d":" | tr '\n' ' ') ) # The given line numbers (array)
START=1 # The offset to calculate lines
IDX=1 # The index used in the name of generated files: file1, file2 ...
for i in "${LINE_NUMBERS[@]}"
do
# Extract the lines using the head and tail commands
tail -n +$START "$INPUT_FILE" | head -n $(( i-START+1 )) > "file$IDX.txt"
(( IDX++ ))
START=$(( i ))
done
# Extract the last given line - last line in the file
tail -n +$START "$INPUT_FILE" > "file$IDX.txt"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment