24664

powershell delete everything after character for every line in a file

Question:

I have a file full of lines like the one below, I would like to use powershell to delete everything after the first "<" in every line in the file

"10.0.0.1","pc1","Microsoft Windows Server 2008 SP2 <100%-accuracy> Microsoft Windows 7 SP0 - SP1, Windows Server 2008 SP1, or Windows 8 <100%-accuracy>"

"10.0.0.2","pc2","Microsoft Windows Server 2008 SP2 <100%-accuracy> Microsoft Windows 7 SP0 - SP1, Windows Server 2008 SP1, or Windows 8 <100%-accuracy>"

"10.0.0.3","pc3","Microsoft Windows Server 2008 SP2 <100%-accuracy> Microsoft Windows 7 SP0 - SP1, Windows Server 2008 SP1, or Windows 8 <100%-accuracy>"

Answer1:

Here is an example of how to truncate a line at a certain delimiter:

$line = '"10.0.0.1","pc1","Microsoft Windows Server 2008 SP2 <100%-accuracy> Microsoft Windows 7 SP0 - SP1, Windows Server 2008 SP1, or Windows 8 <100%-accuracy>"' $linetruncated = $line.Substring(0,$line.IndexOf('<'))

Recommend

  • conversion of list to bitarray in python
  • Passing variables to a function using ggplot in r
  • Joining two SQL Tables with no relationship?
  • Plotting RDA (vegan) in ggplot
  • double precision error when converting to scientific notation
  • python & Mysql: unsupported operand type(s) for -: 'int' and 'tuple'
  • NSMutableArray instance used in a block
  • XOR with Neural Networks (Matlab)
  • pymongo replication secondary readreference not work
  • Compress a file with GZipStream while maintaining its meta-data
  • powershell Get-Counter -ComputerName parameter on Windows 7
  • Xamarin MonoAndroid Azure mobile service InsertAsync
  • Private IP address in reserved subnet range
  • How To Customize ASP.NET Chart Databound To SqlDataSource
  • Specify the x-axis values in ggplot in R
  • Debug.DrawLine not showing in the GameView
  • print() is showing quotation marks in results
  • Make VS2015 use angular-cli ng at build time in a .NET project
  • Android fill_parent issue
  • R - Combining Columns to String Based on Logical Match
  • Using $this when not in object context
  • Read text file and split every line in MSBuild
  • C# - Serializing and deserializing static member
  • How do I fake an specific browser client when using Java's Net library?
  • How reduce the height of an mschart by breaking up the y-axis
  • Get object from AWS S3 as a stream
  • Resize panoramic image to fixed size
  • Sony Xperia Z Tablet not found by adb
  • Volusion's generic SQL folder, functionality
  • Perl system calls when running as another user using sudo
  • Javascript convert timezone issue
  • Why is the timeout on a windows udp receive socket always 500ms longer than set by SO_RCVTIMEO?
  • Why winpcap requires both .lib and .dll to run?
  • Return words with double consecutive letters
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • how to add data labels for bar graph in matlab
  • Load html files in TinyMce
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • How do you join a server to an Active Directory (domain)?
  • coudnt use logback because of log4j