nsedatascrub.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/env bash
  2. # File: nsedatascrup.sh
  3. # Name: D.Saravanan
  4. # Date: 03/12/2020
  5. # Script to scrup the NSE historical index data of the following structure:
  6. # "Date","Open","High","Low","Close","Shares Traded","Turnover (Rs. Cr)"
  7. # "01-Jan-2019"," 10881.70"," 10923.60"," 10807.10"," 10910.10"," 159404542"," 8688.26"
  8. # "02-Jan-2019"," 10868.85"," 10895.35"," 10735.05"," 10792.50"," 309665939"," 15352.25"
  9. # "03-Jan-2019"," 10796.80"," 10814.05"," 10661.25"," 10672.25"," 286241745"," 15030.45"
  10. # "04-Jan-2019"," 10699.70"," 10741.05"," 10628.65"," 10727.35"," 296596655"," 14516.74"
  11. # "07-Jan-2019"," 10804.85"," 10835.95"," 10750.15"," 10771.80"," 269371080"," 12731.29"
  12. # "08-Jan-2019"," 10786.25"," 10818.45"," 10733.25"," 10802.15"," 277697672"," 13433.48"
  13. # "09-Jan-2019"," 10862.40"," 10870.40"," 10749.40"," 10855.15"," 333010535"," 16213.30"
  14. # "10-Jan-2019"," 10859.35"," 10859.35"," 10801.80"," 10821.60"," 254365477"," 12031.26"
  15. # "11-Jan-2019"," 10834.75"," 10850.15"," 10739.40"," 10794.95"," 260792200"," 13084.60"
  16. # Data Source: https://www1.nseindia.com/products/content equities/indices/historical_index_data.htm
  17. echo "Enter NSE data file name: "
  18. read fname
  19. if [ -f $fname ]; then
  20. for n in {2..14..2}; do
  21. cut -d '"' -f $n $fname >file$n.txt
  22. done
  23. # combine data column wise
  24. paste -d ',' file{2..14..2}.txt >result.csv
  25. # remove spaces between the columns
  26. tr -d '[:blank:]' <result.csv >$fname
  27. # delete file{2..14..2}.txt and result.csv
  28. rm file{2..14..2}.txt result.csv
  29. else
  30. echo "Not a regular file."
  31. fi