Wanted to translate two-digit years into 4 digit years for the 1900s only.
Two digits were getting written as 35-37 or 40-50 in the spreadsheet. This needed to be translated to 1935 1936 1937 or 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950.
|
1 2 3 4 5 |
for i in seq 35 37; do echo "$i + 1900" | bc; done 1935 1936 1937 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
for i in seq 40 50; do echo "$i +1900" | bc ;done 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 |
Or
By creating a file named ‘years’ with two-digit years on each line.
67 80
55 60
45 50
|
1 |
$ while read line; do content=$(seq $line); for j in $(echo $content);do echo "$j + 1900"| bc;done;echo ""; Â done < years |
Or another way, which would be ran by also creating separate file called ‘years’ in the same format as above.
|
1 2 3 4 5 |
while IFS='' read -r line || [[ -n "$line" ]]; do #echo "$line" for i in `seq $line`; do echo "$i + 1900" | bc; done echo "################" done < "$1" |
|
1 |
$ bash years.changer.sh years |
Lastly, I needed the output to be put on the same line so instead of line returns I needed spaces..
|
1 2 3 4 5 6 |
#!/bin/bash while IFS='' read -r line || [[ -n "$line" ]]; do for i in `seq $line`; do echo "$i + 1900" | bc; done | tr '\n' ' ' echo "" done < "$1" |
Which outputs
|
1 2 3 4 5 |
1961 1962 1963 1964 1960 1961 1962 1963 1964 1957 1958 1959 1955 1956 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 |
Wanted to have Google Sheets do this automatically. But for now, I’m just using this method and copy/pasting results into the spreadsheet.  If anyone has any suggestions, please let me know.