0

I have one file and replace string :

sample file is:

DP_SESSION_ID is a sting for values DP_SESSION_ID is aplicat "DP_S42SETTACC_TYPE"\1\"02" "DP_SAP_CLIENT"\1\"460" "DP_SAP_COMM_CONNECTION"\1\"JAVA_COMM_TOOL_ANALYZER" "DP_SAP_CONNECTION"\1\"JAVA_TOOL_ANALYZER" "DP_SAP_TOOLBI_CONNECTION"\1\"JAVA_TOOLBI_ANALYZER" "DP_SESSION_ID"\1\"808"

I want search this "DP_SESSION_ID"\1\" sting and replace corresponding number like 808 in file prenatally(windows env), and i wand sing line command in windows bat command or perl command i don't want scrip or program

even i have installed cygwin tool in my server so unix also ok but single line command

server: windows 2008,cygwin x

using tool : datastage server jobs

perl -pi -e 's{" "DP_SESSION_ID"\1\"808 '"}{' "DP_SESSION_ID"\1\"900 '"'"}g' " file name this code is not working

Please give good solution

narendrak
  • 25
  • 6

2 Answers2

1

First, you can't use single-quotes in DOS the way you can in UNIX. Second, you need to specify a backup file/extension when you use "-i" in DOS. Third, I think you skip trying to match all those complicated quotes and go with a simpler approach. It may not be the most efficient (using 2 regex) but it's very readable (to me).

This works for me:

perl -p -i.bak -e "m/\"DP_SESSION_ID\"/ && s/808/900/g" "filename"

Hope that helps!

jimtut
  • 2,366
  • 2
  • 16
  • 37
  • in file same line have double-quotes and same lines don't have double-quotes like "DP_SESSION_ID"\1\" ,/DP_SESSION_ID/ but i want quotes string only – narendrak Feb 24 '14 at 08:15
  • Updated the one-liner to handle quotes around DP_SESSION_ID. – jimtut Feb 24 '14 at 08:21
  • Thank u it's working but a small question i don't need bak file i want change directly file.if there is any option – narendrak Feb 24 '14 at 08:48
  • According to this other item on this website, it can't be done: http://stackoverflow.com/questions/2616865/why-do-i-have-to-specify-the-i-switch-with-a-backup-extension-when-using-active – jimtut Feb 24 '14 at 08:51
  • thank you for ur quick responds – narendrak Feb 24 '14 at 08:58
  • Sure, don't forget to "accept" one of the answers! That's an important part of how StackOverflow works. – jimtut Feb 24 '14 at 13:41
0

in powershell, you can try the command as below:

get-content input.txt |foreach-object {$_ -replace '"DP_SESSION_ID"\\1\\"808"', '"DP_SESSION_ID"\1\"900"'} | set-content output.txt
poiu2000
  • 960
  • 2
  • 14
  • 30