Skip to main content

Posts

Showing posts from June, 2019

Replace column value of text files using awk

AWK is a handy tool to process large text files. Ever came across a need to replace 100 or more text files value in a single column? Of course, the old school method is to do it manually which is definitely time consuming and not efficient at all. Below is a sample code how to replace value in a column for all text files found in the directory specified. #!/bin/bash for file in /home/pc_text/Documents/source/* do xfilename=$(basename $file) #echo "$xfilename" if you need to display the filename while the code is running awk 'FNR==1{print $0}' $file >> /home/pc_text/Documents/output/$xfilename awk 'NR>1{print $1 , $2 , $3 , $4   , "0.873" , $6 , $7 }' $file >> /home/pc_text/Documents/output/$xfilename done Code explanation: for file in /home/pc_text/Documents/source/* - get all text files for processing xfilename=$(basename $file) – get all the filename of the text files awk

Error: the type or namespace name does not exist in the namespace using visual studio 2017

When compiling an error will occur that a name space does not exist. An example error like the message below: The type or namespace name 'Microsoft.Office.Interop.Outlook' does not exist in   the namespace 'Microsoft'    (are you missing an assembly reference?) The system is trying to find a reference for a specific namespace or dll. One solution for this is to add the reference to the missing namespace. Find the “solution explorer” window like the image below: After opening the “solution explorer” window, right click the name of the project just below the solution explorer. Beside the C# icon. A new window will open like the image below. Click “Add”, then click “Reference”. After clicking “Reference”, the “Reference Manager” window will open. Click “COM” option, then use the filter option to go directly to the desired namespace or reference. Since the error is a Microsoft namespace, type “Microsoft” and “Microsoft

Copy or migrate shared folders to another server

Migrating or copying files to another server and retaining the permissions is a common task when migrating a file server. If all permissions are successfully retained it will make the migration seamless and nobody will ever notice that a migration has taken place. If there are shared folders and with different permissions, re-sharing the folder by scratch is just time consuming and giving access denied to users will be inevitable. But how to copy files and folders, like it was exactly done on the old server? In Windows environment, just 3 steps are needed. 3 steps sound easy and quick. Steps below will work for NTFS permissions and folder access rights solely depends on it. a.       Copy the files to the new server and retaining its permissions while files and folders are being copied b.       Export the shares registry (old server) c.       Import the shares registry (new server) The link below from Microsoft website shows how xcopy can copy folder

PowerShell Insert Multiple Lines or text to another file dynamically

Copying and pasting text to another file is a common thing to do, copy and paste done. Boom! In PowerShell scripting copying and pasting text from one file to another dynamically isn’t as easy as it is done in a spreadsheet or document. Dynamically while the code is running  and doing things in the background without human intervention. As the odds say, if there’s a will there’s a way. And making things efficient and easy is a good way in life. If ever a scenario occurs that you need to copy text or lines in a file from one file to another, without breaking the code execution. Script below works just fine. Just insert the code where it is needed. PowerShell code snippet to add lines anywhere on the text file, whether at the top, end or at the middle. #================================ $reader = [ System.IO.File ]:: OpenText( "D:\test-read-paste\main1.txt" ) #get-content can also be used $lineNumberx = 3 #adjust this number where you need to