Edit the files in folder
1. Chop off few words from the 1st line
2. Reads a particular word from the 1st line and then replaces that with some other word.
More particularly
1. Removes "p tw" from the 1st line.
2. Replace the 3rd word(in line 1) with "0" in all the lines except line 1.
$cat sample
p tw 5 4
1 2
5 2
3 4
1 5
$cat required-sample
5 4
1 2
0 2
3 4
1 0
#!/bin/bash
for file in `ls *.gr`
do
nodes=`awk 'NR==1{print $3}' $file` #takes the 3rd word which is n or |V|
sed -i "1s/p tw //" $file #chops the p and tw from the 1st line
echo $file - done $nodes
sed -i '2,$ s/$nodes/0/g' $file #f
done
for file in `ls *.gr`
do
nodes=`awk 'NR==1{print $3}' $file` #takes the 3rd word which is n or |V|
sed -i "1s/p tw //" $file #chops the p and tw from the 1st line
echo $file - done $nodes
sed -i '2,$ s/$nodes/0/g' $file #f
done
Thanks to Vijay R
No comments:
Post a Comment