2

I need to remove part of a line in a group of files.

Example line:

TRN*1*301444/05-13-20*6549873211~

I need it to be this instead (remove the portion /05-13-20):

TRN*1*301444*6549873211~

The forward slash up to the last asterisk need to be removed and the new line needs to be retained in the file.

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
wbl
  • 21
  • you want to remove the part from / to * or the 8 characters following / or anything that looks like a date? – Neil McGuigan Sep 08 '16 at 17:59
  • Answers you got, here's some material for learning more about sed and regexes: http://unix.stackexchange.com/tags/sed/info and http://unix.stackexchange.com/q/2434/170373 – ilkkachu Sep 08 '16 at 18:11

2 Answers2

3

With sed:

sed -n 's_/[^*]*__p'
  • /[^*]* matches the portion from / uto next *, and it is then replaced with null, as we have used empty string in the replacement

Example:

% sed -n 's_/[^*]*__p' <<<'TRN*1*301444/05-13-20*6549873211~'
TRN*1*301444*6549873211~
heemayl
  • 56,300
0

Regular expressions can be used to do that. They are available in most languages, but perl is the regex leader. There are many ways to do what you asked with regex but here is one example;

perl -pi -e 's/\/.*\*/*/g' file.txt
user1133275
  • 5,574