[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 369
  • Last Modified:

Need sed help

I need to know how to delete a line using a wildcard using sed.  The line begins with
!R! BARCODE.  The rest of the line can varies depending on the item.
So how do I tell sed to delete the !R! BARCODE and everything afterwards to the end of the line.  I don't want to actually remove the line, just all the test on the line that begins with !R! BARCODE.
0
9thTee
Asked:
9thTee
  • 2
  • 2
1 Solution
 
woolmilkporcCommented:
sed 's/^!R! BARCODE.*//' inputfile > outputfile

This will create a changed "outputfile" leaving "inputfile" as is.

If your sed supports it you can use the "-i" flag to change "inputfile" in place and create an unchanged  backup file "inputfile.bak" in the same go:

sed -i.bak 's/^!R! BARCODE.*//' inputfile
0
 
tel2Commented:
> The line begins with !R! BARCODE.
> I don't want to actually remove the line, just all the test on the line that begins with !R! BARCODE.


So do you want to be left with a blank line, 9thTee?
0
 
9thTeeAuthor Commented:
Yes tel2, a blank line.
0
 
tel2Commented:
In that case, woolmilkporc's solutions should work for you.
0
 
9thTeeAuthor Commented:
Perfect!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now