Reputation: 21
I have a file like this
/device/000:004:00.7/vmkname = "vmnic8"
/device/000:005:00.0/vmkname = "vmnic0"
/device/000:005:00.1/vmkname = "vmnic4"
/device/000:005:00.2/vmkname = "vmnic10"
/device/000:005:00.3/vmkname = "vmnic11"
.... 15 lines
I want to change it like this:
/device/000:004:00.7/vmkname = "vmnic0"
/device/000:005:00.0/vmkname = "vmnic1"
/device/000:005:00.1/vmkname = "vmnic2"
/device/000:005:00.2/vmkname = "vmnic3"
...till
/device/000:005:00.3/vmkname = "vmnic15"
Upvotes: 2
Views: 149
Reputation: 185025
Awk version :
awk '{if ($1) {print $1, $2, "\"vmnic"c++"\""}else{print}}' FILE
you can redirect output to a new file.
Upvotes: 2
Reputation: 185025
See :
#!/bin/bash
c=0
while read a b; do
[[ "$a" ]] || continue
echo "$a = \"vmnic$((c++))\""
done < FILE > NEW_FILE
Upvotes: 0
Reputation: 11606
This should do:
count=0
for i in `cat input_file.txt | cut -d " " -f1`
do
echo $i = \"vmnic$count\" >> output_file.txt
count=`expr $count + 1`
done
Just make sure your input_file.txt doesn't have any empty lines.
Upvotes: 1