This blog is the continuation of my previous blog , where I have explained the difference between PowerShell and Shell Scripting through 5 different scenarios. Here , in this Blog , I will take few more commands and will show the difference between them. Consider one file in windows and one file in Linux with same Data.
![](https://www.allabouttechnologies.co.in/wp-content/uploads/2022/10/image.png)
![](https://www.allabouttechnologies.co.in/wp-content/uploads/2022/10/image-1.png)
Print selected column of a file
Windows use below commands.
Need to mention what all columns are required.$headers=@(
"COL1"
"COL2"
)
Use import csv command to display data for above mentioned headers.Import-Csv -Path .\PowerShell_Scripting.txt -Delimiter '|' | Select $headers
![](https://www.allabouttechnologies.co.in/wp-content/uploads/2022/10/image-2.png)
Linux uses Awk Command.cat linux.txt | awk -F "|" '{print $1 "|" $2}'
![](https://www.allabouttechnologies.co.in/wp-content/uploads/2022/10/image-3.png)
Record Count in each file
Windows uses “Get-Content” and “get-Children”. Created same file with different name. See the below SS.
![](https://www.allabouttechnologies.co.in/wp-content/uploads/2022/10/image-6.png)
$GetFileNames= get-childitem -name "*.txt"
foreach ($a in $GetFileNames) { $a
(Get-Content $a).Length
}
![](https://www.allabouttechnologies.co.in/wp-content/uploads/2022/10/image-7.png)
Linux use “for” and “Awk” command to get total number of records in each file. Here, I have replicated same file twice. See the below SS.
![](https://www.allabouttechnologies.co.in/wp-content/uploads/2022/10/image-4.png)
Below command to use to fetch total count in each file.
for file in ls -lrt *.txt | awk '{print $NF}'; do fileCount=cat $file | wc -l ; echo "Name of the file: " $file " Record Count is :" $fileCount; done
![](https://www.allabouttechnologies.co.in/wp-content/uploads/2022/10/image-5-1024x61.png)
Sum of Particular Field in each file & for Loop
Windows use “Measure-Object” to get sum of particular field.$GetFileName=get-childitem -name "*.txt"
foreach ($a in $GetFileName) {$sum=Import-Csv $a -Delimiter '|' |Measure-Object 'COL3' -Sum
'FileName is '+$a + ' & sum of COL3 is : {0:n2}' -f $sum.Sum
}
![](https://www.allabouttechnologies.co.in/wp-content/uploads/2022/10/image-9.png)
Linux using “sum” and “Awk” commands. Here , It will sum up the third field COL3.for file in ls -lrt *.txt | awk '{print $NF}'; do sum_col3=cat $file | awk -F "|" '{ sum += $3 } END { print sum }'; echo "Name of the file: " $file " Sum of COL3 is :" $sum_col3 ; done
![](https://www.allabouttechnologies.co.in/wp-content/uploads/2022/10/image-8-1024x47.png)
Get Current Location or Path
Windows use Get-Location command.
![](https://www.allabouttechnologies.co.in/wp-content/uploads/2022/10/image-10.png)
Linux use “pwd” command.
![](https://www.allabouttechnologies.co.in/wp-content/uploads/2022/10/image-11.png)