Ok, so to confirm, you want all records where the VAT_Reg number is less than 11 characters, and not blank correct?
yes… exactly what I want … thanks
That is a very simple addition to the existing command
Import-Csv input.txt -delimiter '|' | Where-Object {$_.VAT_Reg -AND $_.VAT_Reg.Length -lt 11}
The in the above code I added to the Where-Object Cmdlet and additional comparison, $_.VAT_Reg
Leaving that value by itself tells the Where-Object Command to check the VAT_Reg field in the current record to see if there is a value there. If there is no value, it returns $false and is not sent to the out put. If there is a value there, it continues on and validates the second condition which requires the length to be less than 11 characters. So the whole command together does this:
- Get Imports the input.txt file and splits it into columns based on the ‘|’ delimiter
- For each record/row of data in the input file, it checks to see if the VAT_Reg column/field for that row has a value and that the value is less than 11 characters
- If both conditions were met, the record/row is sent to the output and is subsequently displayed on the screen.
Thanks a ton Curtis and Dave for giving your valuable time. Finally it is started showing result and the output what I want and thanks for the detail explanation.
Thanks & Regards
Ankit