I need to insert <filename + comma> into each line of multiple files.
Any idea how to script that?
Regards,
Manu
I need to insert <filename + comma> into each line of multiple files.
Any idea how to script that?
Regards,
Manu
Can u give some examples please??
Sources filenames:
<DeviceName>.Inventory.<Date>.txt
<DeviceName>.Inventory.<Date>.txt
<DeviceName>.Inventory.<Date>.txt
File content:
PID: XX, S/N: YY
PID: XX, S/N: YY
PID: XX, S/N: YY
I would like to add DeviceName in the content:
DeviceName, PID: XX, S/N: YY
DeviceName, PID: XX, S/N: YY
DeviceName, PID: XX, S/N: YY
[skrynesaver: ~/tmp]$ cat dev.test.today.txt
PID: XX, S/N: YY
PID: XX, S/N: YY
PID: XX, S/N: YY
[skrynesaver: ~/tmp]$ perl -e 'for $file (@ARGV){open (device , "<" , $file);open (temp ,">", "temp.dev");($dev)=$file=~/^([^.]+)./; while(<device>){print temp "$dev, $_";}close temp; close(device);rename("temp.dev" , "$file");}' *.txt
[skrynesaver: ~/tmp]$ cat dev.test.today.txt
dev, PID: XX, S/N: YY
dev, PID: XX, S/N: YY
dev, PID: XX, S/N: YY
[skrynesaver: ~/tmp]$
```[/b]
Dear Skrynesaver, Just Great, work as expected
How to adapt $dev because i forget the country name in the source filenames:
<Country>.<DeviceName>.Inventory.<Date>.txt
I would like:
country, dev, PID: XX, S/N: YY
or if it is easier:
country.dev, PID: XX, S/N: YY
Try this...
awk '{split(FILENAME,arr,"."); print arr[1]", "arr[2]", " $0 > FILENAME}' *.txt
--ahamed