Skip to content

Instantly share code, notes, and snippets.

@EricLondon
Last active September 21, 2018 13:52
Show Gist options
  • Save EricLondon/f7d6eec221a69e4a6b9837c403554dd2 to your computer and use it in GitHub Desktop.
Save EricLondon/f7d6eec221a69e4a6b9837c403554dd2 to your computer and use it in GitHub Desktop.
Shell script to append missing character to end of line based on count of occurrence
#!/usr/bin/env bash
INPUT_FILE=some-input-file.txt
OUTPUT_FILE=output.txt
while read p; do
pipecount=$(echo $p | awk -F"|" '{print NF}')
if [ $pipecount == 45 ]; then
echo "$p|" >> $OUTPUT_FILE
else
echo $p >> $OUTPUT_FILE
fi
done < $INPUT_FILE
#!/usr/bin/env ruby
input_file = './some-input-file.txt'
output = './output2.txt'
output_handle = open(output, 'w')
File.open(input_file, 'r') do |file_handle|
file_handle.each_line do |line|
if line.count('|') == 46
output_handle.write(line)
else
output_handle.write(
line.insert(line.index("\n"), '|')
)
end
end
end
output_handle.close
puts "done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment