Thursday, July 4, 2019

Merge multiple .csv files available in same folder using CMD command

This is a trick which can save you a lot of time when working with a dataset spread across multiple CSV files. Using a simple CMD command it is possible to combine all the CSV’s into a single .CSV file.

Command:
c:\> copy *.csv combine.csv

that's it. Hope this will save your time.

Wednesday, July 3, 2019

Iterate/Loop over a JSON structure

This is an example for looping JSON structure and reading values.

var s = [{key:1,value:"abc"},{key:2,value:"def"},{key:3,value:"xyz"},{key:1,value:"pqr"}]

for(var i in s)
    console.log ("Key :" + s[i].key + " - Value :" + s[i].value)

//Output
Key :1 - Value :abc
Key :2 - Value :def
Key :3 - Value :xyz
Key :1 - Value :pqr

Tuesday, June 25, 2019

File Row Count using Batch file in a directory

Copy and Paste following code in a batch file, that will count rows in file (csv, txt, etc.,) available in the directory.

@ECHO OFF
setlocal enabledelayedexpansion
for %%f in (*.csv) do (
  set /p val=<%%f
  find /v /c "" %%f
)

Row count with DOS "Find Command"

Windows find command :

Using ‘Find’ command,  we can search for specific text in a set of files. Find below the syntax of this command with examples. Note that windows find command is different from the Linux find command in functionality. Linux find command is used to search for files that match the given criteria. But the windows find command is useful to search files for the lines that match the given string. The windows command that matches partially with Linux find command’s functionality is dir command.

Syntax and Examples

Find the lines of a file that have the specified string
find "string" filename
Ex:

C:\>find "Windows" C:\boot.ini
---------- C:\BOOT.INI
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional" /noexecute=optin /fastdetect


To print line numbers along with the lines
find /N "string" filename
Ex:

C:\>find /N "Windows" C:\boot.ini
---------- C:\BOOT.INI
[5]multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional" /noexecute=optin /fastdetect



To ignore case in searching for the string, we can add /I switch.
find /I /N "string" filename
In the below example, we don’t find any matching lines when we search for ‘windows’. In the next command, I have added /I and it shows the matching line ignoring the case differences.

C:\>find /N "windows" C:\boot.ini

---------- C:\BOOT.INI

C:\>find /N /I "windows" C:\boot.ini

---------- C:\BOOT.INI
[3]default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS
[5]multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional" /noexecute=optin /fastdetect


To find the lines that are not matching with the given string:
We can use /V switch for this case. Please find the command syntax below.

find /V  "string" filename
Ex:

C:\>find /N "windows" C:\boot.ini
---------- C:\BOOT.INI

C:\>find /N /I "windows" C:\boot.ini

---------- C:\BOOT.INI
[3]default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS
[5]multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional" /noexecute=optin /fastdetect




Reference Site


Tuesday, June 18, 2019

How to use Filter with JSON Data

// JSON Data

var jd = JSON.parse('[{"status":"Pass","Marks":98,"subject":"English"},{"status":"Pass","Marks":99,"subject":"Math"},{"status":"Fail","Marks":32,"subject":"Science"},{"status":"Fail","Marks":30,"subject":"History"},{"status":"Pass","Marks":95,"subject":"Computer"}]')


// use filter property to get each item with the condition match as Status as PASS (we are using === to validate they type and return if condition get true.)

var fd = jd.filter(function(item){
      return (item.status === "Pass");
});

result will be.

fd = [{"status":"Pass","Marks":98,"subject":"English"},{"status":"Pass","Marks":99,"subject":"Math"},{"status":"Pass","Marks":95,"subject":"Computer"}]

Tuesday, June 11, 2019

Integer value with leading zero using JavaScript



prefix_zero(10,4) // output 0010

function prefix_zero(num, size) {
    var s = num+"";
    while (s.length < size) s = "0" + s;
    return s;
}


Tuesday, May 28, 2019

10 Excel Skills and Top 10 Sites

10 Excel Skills that can help you analyze data like a pro:
  1. Sparkline
  2. Power Pivots
  3. Conditional Formatting
  4. Text Formulas
  5. Slicers
  6. Flash Fill
  7. Charts
  8. Vlookup
  9. IF Formulas
  10. Quick Analysis