Last active
September 21, 2018 13:52
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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