AWK/SED help

Hi, can anyone help me out with this. I have a text file with multiple number of lines containing(2 columns, no headers):
384 gui\common\gui\container\PropertyPanel.java
5 gui\container\PropertyTableCellUIDeterminator.java
15 gui\container\TreePageNode.java
71 gui\container\TreePagePanel.java
Now i need to replace the first column with a string "M:\nmattam\" so that the output should be like:
M:\nmattam\gui\common\gui\container\PropertyPanel.java
M:\nmattam\gui\container\PropertyTableCellUIDeterminator.java
M:\nmattam\gui\container\TreePageNode.java
M:\nmattam\gui\container\TreePagePanel.java
Thanks in advance. I tried with SED to add string at the beginning but not sure how to replace.

Something like this:

awk -v va='M:\\nmattam\' '{ print va $2 }' inputfile > opfile

or,

awk '{gsub(/^.* /,"M:\\nmattam\\",$0);print}' file

Thanks panyam for quick help but i am not sure what it exactly is? Can you elaborate? I just tried executing this command but nothing happened to change.

Try out this

sed '1,10s/^[[:digit:]]\{1,5\}/M:\\nmattam/g' <filename>

The awk statement print's the second column of the file by appending the variable to it (which is stored in va).

The same worked for me, the needed output will be in the 'opfile'.

Note that this code wont modify the input file.

oky, i tried sed '1,10s/^[[:digit:]]\{1,5\}/M:\\nmattam/g' sclc_test.txt but it is replacing every digit occurances. I just wanted only column one to be replaced with the string.

---------- Post updated at 12:28 PM ---------- Previous update was at 12:21 PM ----------

panyam, awk doesnt work for me. I find sed command working. Can we try the same awk -v va='M:\\nmattam\' '{ print va $2 }' inputfile > opfile with sed. I am using windows command prompt.

did you try another awk solution?

regarding sed, yes you can do in the same way.

try this

 
$ cat sample
384 gui\common\gui\container\PropertyPanel.java
5 gui\container\PropertyTableCellUIDeterminator.java
15 gui\container\TreePageNode.java
71 gui\container\TreePagePanel.java
 
$ awk '{print "M:\\nmattam"$2}' sample
M:\nmattamgui\common\gui\container\PropertyPanel.java
M:\nmattamgui\container\PropertyTableCellUIDeterminator.java
M:\nmattamgui\container\TreePageNode.java
M:\nmattamgui\container\TreePagePanel.java
 

Do you have the option of copying some exe files onto your computer? If yes, then you should check out: Native Win32 ports of some GNU utilities or The Berkeley Utilities

These are, as the first title suggests, windows ports for some unix commands. Copy these exe's somewhere, and add that location to your PATH variable. I would suggest giving cygwin a spin, but that might be overkill for what you are trying to accomplish here.

Good luck,
Jay.

yes anchal_khare, i tried gawk and it works but the output looks a bit confusing. Can i add '\n' to retain the lines as it existed in the gawk command?

/home1->cat f
384 gui\common\gui\container\PropertyPanel.java
5 gui\container\PropertyTableCellUIDeterminator.java
15 gui\container\TreePageNode.java
71 gui\container\TreePagePanel.java
/home1->awk '{gsub(/^.* /,"M:\\nmattam\\",$0);print}' f
M:\nmattam\gui\common\gui\container\PropertyPanel.java
M:\nmattam\gui\container\PropertyTableCellUIDeterminator.java
M:\nmattam\gui\container\TreePageNode.java
M:\nmattam\gui\container\TreePagePanel.java
/home1->

Is that not the o/p you are getting?
by the way, xoops's solution is more simpler, you can use that.

sed 's/[^ ]* */M:\\nmattam\\/' infile
while read size relpath; do
  echo 'M:\nmattam\'"$relpath"
done<infile

Thanks to all for your effort, gawk '{print "M:\\nmattam"$2}' works good for me. That was great help. Thanks all.

Try nawk/gawk which ever is available in your system.