×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

extract rows from csv

extract rows from csv

extract rows from csv

(OP)
Hi
I'm trying to extract rows that match a pattern (3 characters and 8 digits) from a csv file and output them to a new csv

CODE --> ps1

#Import the CSV file with all the data.
$csv = Import-CSV J:\CanvasData\users_utf8nobom.csv 
#Process the CSV file one row at a time 
foreach ($row in $csv) { 
#Each column is accessed using the column header. 
#We can use the -not operator to specify 'doesn't match'.      
if ($row.user_id -eq "\b[\D[3}\d{8}]\b")
{ 
#... Export that row to a new CSV file.        
$row | Export-CSV J:\Temp\teacherlist.csv  -Append -NoTypeInformation   
 } 
} 

an example of the csv file is below
user_id status
MCN18158364 active
901658 active
W00054 active
MCN17125917 active

RE: extract rows from csv

I am far from expert, but...

How about -match rather than -eq?

Tom Morrison
Consultant

RE: extract rows from csv

"\b[\D[3}\d{8}]\b"

... is that correct?

Just my $.02

"What the captain doesn't realize is that we've secretly replaced his Dilithium Crystals with new Folger's Crystals."

--Greg

RE: extract rows from csv

Quote:


should probably be \b\D{3}\d{8}\b

if ($row.user_id -match "\b\D{3}\d{8}\b")

Yeah.... the addition of the braces [] would say "any match of the characters in the braces" I believe...
I think your match should work....

Just my $.02

"What the captain doesn't realize is that we've secretly replaced his Dilithium Crystals with new Folger's Crystals."

--Greg

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close